Is the kill
function in Linux synchronous? Say, I programatically call the kill
function to terminate a process, will it return only when the intended process is terminated, or it just sends the signal and return. If that is the case, how can I make it wait for the intended process to be killed?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
kill
cannot be synchronous as it only sends a signal. The target process might ignore incoming signals (cf.SIG_IGN
) so there's no guarantee regardingkill
's effect.It shouldn't be difficult to make an experiment verifying this hypothesis. Start process A and make it handle
SIGTERM
with a 10 second sleep before dying. Then start process B, which delivers aSIGTERM
to A and exits immediately.The kill system call does not wait for the other process to do anything. The signal is posted to the target process and the system call returns. The target process notices the signal when it is scheduled to run.
No, since it doesn't kill anything, it only sends a signal to the process.
By default this signal can even be blocked or ignored.
You can't block
kill -9
which represents sendingSIGKILL
To wait for the process to die:
man 2 kill
man wait
See also
man 7 signal
for more details about Unix signals.