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
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:
Then, from sudo you can run:
Then, later:
I hope you find this helpful.