Question : Sending a signal to processes on a queue


If I call wait_event_interruptible(q, bCondition), the current kernel process will sleep until either a signal is received, or until the condition is true.

The question is, how do you send a signal to all processes on the queue?

Also, I want the kernel process to return an error to the user mode process, to say that it was unable to complete the call because the device was removed.  Which error code should I return?

Answer : Sending a signal to processes on a queue

sunnycoder's comment doesn't seem to address the question.  It's true that calling wake_up() wakes up the processes in the queue, but the question was how do you send signals to the processes?

I suspect that sending signals to the processes isn't really what  Nick75 needs, but  then simply waking up the processes, which will just go back to sleep since the condition isn't true, wouldn't either.

To send signals, just walk the wait queue (it's just a linked list) and  call send_sig on each.

This is the right thing to do if you want  the user space program to receive a signal, which typically terminates the process.  

But the second question, which asks about an error code to return to the user program, implies you don't really want to send a signal.  You just want the system call that is blocked to complete with an error.

For that, you simply want to define the waited-for condition such that  it is true when  the device has been removed.  E.g. the condition could be "data is available  from the device or the device no longer exists."

I don't believe ENOENT is appropriate here.  I don't see any connection between a device being removed and a directory entry not existing.  I would go with ENODEV (same as you'd get if the device never existed in the first place) or  just EIO.
Random Solutions  
 
programming4us programming4us