Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to execute an application (gnutls-cli) as another user and send a signal to it (SIGALRM). Unfortunately this does not work:

sudo -u myuser gnutls-cli -p smtp imap.gmail.com --starttls &
sudo -u myuser kill -ALRM $!

gnutls-cli is a child of the sudo process, that is I got the following process tree:

\_ sudo -u myuser gnutls-cli -p smtp imap.gmail.com --starttls
    \_ gnutls-cli -p smtp imap.gmail.com --starttls

this means the signal is sent to the outer sudo process. Obviously this does not work at all.

Is there any way to get sudo to exec the subprocess directly or to forward signals to its child?

Thanks

share|improve this question
add comment

1 Answer

A quick look at the man pages for sudo and sudoers reveal nothing obvious to solve this problem, but can I offer an alternative solution?

Wrap the original program in a script that will save the spawned pid# into a pidfile, which you can reference later. For example:

/home/myuser/scripts/gnutls-cli-wrapper.sh:

gnutls-cli $@ &
echo $! > /home/myuser/var/gnutls-cli.pid

Then, from sudo you can run:

sudo -u myuser /home/myuser/scripts/gnutls-cli-wrapper.sh -p smtp imap.gmail.com --starttls &

Then, later:

sudo -u myuser kill -ALRM $(cat /home/myuser/var/gnutls-cli.pid)

I hope you find this helpful.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.