See for yourself:

% sudo sleep 100 &
[1] 23272
% pkill sleep
pkill: killing pid 23275 failed: Operation not permitted
% fg
[1]  + running    sudo sleep 100

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 and SIGINT — none get delivered.

  • Ctrl+C does send the SIGINT.

    % cat script.sh
    trap 'echo "SIGINT caught!"' SIGINT
    while true
        sleep 1
    % ./script.sh
    ^CSIGINT caught!

So it does look like we have a contradiction here.

  • See Signal handling section in man sudo. Aug 4, 2019 at 19:14
  • contradiction with what? when you press Control-C (VINTR), it's the kernel which is sending the SIGINT signal to the foreground job, not some userland process, privileged or not.
    – mosvy
    Aug 4, 2019 at 19:29
  • @ArkadiuszDrabczyk It says it relays signals. But sudo is itself running as root, so how does it receive those signals in the first place? Aug 4, 2019 at 19:38
  • @mosvy Contradiction between that I cannot signal to a process that runs as another user without being root myself and that I can signal a process running as another user via unprivileged terminal. Why do I feel like you are trying to be condescending rather than helpful? If you have something to say, then go ahead and write a useful answer. Aug 4, 2019 at 19:42
  • I have no idea why you feel like that, or why you assume that I'm talking out of my ass when I tell you that it's the kernel which is sending the signal. I don't want to interract further, but I have news for you -- you can not only signal the process, but "fake" its standard input via the "unprivileged terminal".
    – mosvy
    Aug 4, 2019 at 19:47


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.