after

Echo a string after process dies
git clone _git@git.zakaria.org/after.git
Log | Files | Refs | README | LICENSE

commit bae8f409771a3efb197e0c2aa23ce0f3e656997e
parent 9f7d081a8c593948136742d0b347794e79c9d6a0
Author: Benjamin Baier <programmer@netzbasis.de>
Date:   Tue,  5 Jan 2021 13:04:31 +0100

Only print string if process was running in the first place.
Adapt verbose messages and exit code.

Diffstat:
Mafter.c | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/after.c b/after.c @@ -74,6 +74,7 @@ main(int argc, char *argv[]) { int i, ch, entries; int pid = 0; + int found = 0; char *pname = NULL, *cmd = NULL; char errbuf[_POSIX2_LINE_MAX]; @@ -131,13 +132,19 @@ main(int argc, char *argv[]) pname_is_in(pname, kinfo, entries) == 0 : pid_is_in(pid, kinfo, entries) == 0 ) { + found = 1; kinfo = get_proc_list(kd, &entries); debug_print("waiting..."); sleep(1); } - debug_print("process not in process list (died?)."); - printf("%s\n", cmd); + if (found) { + debug_print("process died."); + printf("%s\n", cmd); + } else { + debug_print("process not in process list."); + exit(1); + } return 0; }