Alert when running process finishes
Something like this?
(while kill -0 $pid; do sleep 1; done) && echo "finished"
Replace $pid
with the process id and echo "finished"
with whatever you want to do when the process exited.
For example:
(while kill -0 $pid; do sleep 1; done) && mail ...
I wrote process_watcher.py
process_watcher --pid 1234 --to [email protected]
Currently, email body looks like:
PID 18851: /usr/lib/libreoffice/program/soffice.bin --writer --splash-pipe=5
Started: Thu, Mar 10 18:33:37 Ended: Thu, Mar 10 18:34:26 (duration 0:00:49)
Memory (current/peak) - Resident: 155,280 / 155,304 kB Virtual: 1,166,968 / 1,188,216 kB
[+] indicates the argument may be specified multiple times, for example:
process-watcher -p 1234 -p 4258 -c myapp -c "exec\d+" --to [email protected] --to [email protected]
optional arguments:
-h, --help show this help message and exit
-p PID, --pid PID process ID(s) to watch [+]
-c COMMAND_PATTERN, --command COMMAND_PATTERN
watch all processes matching the command name. (RegEx pattern) [+]
-w, --watch-new watch for new processes that match --command. (run forever)
--to EMAIL_ADDRESS email address to send to [+]
-n, --notify send DBUS Desktop notification
-i SECONDS, --interval SECONDS
how often to check on processes. (default: 15.0 seconds)
-q, --quiet don't print anything to stdout
Ceate a GitHub issue if you need any improvements to it.
I use &&
to execute a second command when the first is finished successfully. Here some examples:
Delete a big folder and beep:
rm -rv ~/tmp && beep
Compile a kernel and send an email:
make && mail -s "Compilation is done" [email protected]
Is this a good way to solve your problem? In another case, you can add an ||
and a third command in case of failure.
Also, an shell script could receive the exit status ($?
) of your command, and with if/else
and loops you can do whatever you want.