Suppose I run a command in one shell session, for example bash -c 'apt-get update && apt-get upgrade'
. 5 minutes later I decide to go outside for a snack, and realize I forgot to add some form of notification mechanism for whether exit was success or failure.
Well, what do I now ? If only I could query from another terminal the exit status of that other command ( or specifically, that PID), maybe I could after all display some sort of pop up. So the question is: how can I query exit status of an already running process from another terminal ?
In other words,
GIVEN that I have a running process in terminal A AND its PID is known
WHEN I execute some command in terminal B
THEN I should be able to know if process in terminal A finishes with exit status 0 or exit status >1.
wait
to get the code of a background process in your current shell, after it terminates, but I could not find anything that would allow querying other shells. Simply monitoring whether a process is still running and raising an alert once it exits is also trivial again, but not finding out its exit code. The only way I could possibly think of would require preparing your shell'sPROMPT_COMMAND
to store the last exit code in a tempfile or similar accessible location. Would that be an option?