简体   繁体   中英

how can i check if a process got a signal while he is in wait queue linux 2.4

i am implementing a module that acts as a fifo, in order to prevent two processes from accessing a buffer that is used for reading/writing i used a semaphore,when a semaphore blocks a process it moves it into the wait queue, my question is how can i check if while that process is waiting it received a signal because if it did then i would like to stop what ever that process was doing (reading or writing) and return an error. the only function i am familiar with is sigpending(sigset_t *set) but i am not really sure how to use it, any help will be appreciated. (when i say read/write i mean the function that were implemented for the module in fops)

To allow a sleeping task to be woken up when it receives a signal, set the task state to TASK_INTERRUPTIBLE instead of TASK_UNINTERRUPTIBLE . Such a signal wakeup happens completely independently from any wait queues, so it must be checked for separately (with signal_pending() ).

A typical wait loop looks like this:

DECLARE_WAITQUEUE(entry, current);
...
if (need_to_wait) {
    add_wait_queue(&wq, &entry);
    for (;;) {
        set_current_state(TASK_INTERRUPTIBLE);
        if (!need_to_wait)
             break;
        schedule();
        if (signal_pending(current)) {
            remove_wait_queue(&wq, &entry);
            return -EINTR; /* or -ERESTARTSYS */
        }
    }
    set_current_state(TASK_RUNNING);
    remove_wait_queue(&wq, &entry);
}
....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM