See for yourself:
% sudo sleep 100 &
[1] 23272
% pkill sleep
pkill: killing pid 23275 failed: Operation not permitted
% fg
[1] + running sudo sleep 100
^C
%
How is it that the terminal is able to terminate the privileged sleep
process here?
I verified and ascertained two things:
It is forbidden to signal to processes that belong to any other user, even to
nobody
.% sudo -u nobody sleep 100 & [1] 24321 % pkill sleep pkill: killing pid 24324 failed: Operation not permitted
I tried this with
SIGTERM
,SIGKILL
andSIGINT
— none get delivered.Ctrl+C does send the SIGINT.
% cat script.sh #!/bin/sh trap 'echo "SIGINT caught!"' SIGINT while true do sleep 1 done % ./script.sh ^CSIGINT caught!
So it does look like we have a contradiction here.
Signal handling
section inman sudo
.VINTR
), it's the kernel which is sending theSIGINT
signal to the foreground job, not some userland process, privileged or not.sudo
is itself running asroot
, so how does it receive those signals in the first place?