Score:0

Send signal to process and wait x seconds for it to disappear

jp flag

I would think this is a common idiom in Linux world so my question is if there's some build-in functionality for it ?

Something like:

Args:

$PID  - the process to send signal to
$SIGNAL_NAME   - the signal to send to the process
$WAIT_TIME    - number of seconds to wait for $PID to disappear

The command I'm looking for would send the process $PID the $SIGNAL_NAME and then wait synchronously for $WAIT_TIME until the $PID process disappears. Command would have some proper exit code of course.

I can write such script quite easily. I would just expect it to be a common requirement? Perhaps a shell build-in ?

Score:0
jp flag

Arghh

I was hoping for an option on the kill command or something that would do this trick for me.

The best solution I've found so far is:

kill -$SIGNAL_NAME $PID; timeout ${WAIT_TIME}s tail -f /dev/null --pid $PID

which works fine assuming that the tail command supports the --pid option. However, this is a prime example of one of (many) Linux command constructs that requires a significant amount of time and investigation to understand what it really does. In 1 months time I will have forgotten why the above works. :-(

The killall --wait command seems to be pretty close to a build-in solution to the problem except that it doesn't accept PID as an argument.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.