Skip to content
Advertisement

How to implement a process overseeing another process?

Currently at my workplace I have a script named “batch launcher” (written in bash), which is supposed to oversee the execution of batches, logging their output and processing the return code of the batch. This is currently done via env call within this “batch launcher”:

env $BATCH_ENV $BATCH_NAME $BATCH_OPTIONS >> $OUT_FILE 2>&1

Several days ago, one of the batches written in perl made a kill call on PGID (to eliminate all forked children), and since “batch launcher” shares PGID with anything it spawns, it got killed as well by this call.

How should I properly ensure that any PGID kill call will leave “batch launcher” intact, and report back that the process it was overseeing was killed?

I have so far heard of setsid -w command to solve this issue, but I was unable to get it working in combination with env call.

Advertisement

Answer

I have made the stupid mistake of consulting online documentation rather than calling man in the system where I currently work. This page states that setsid supports flags, dated July 2014. My man page is dated November 1993 (I work on RHEL 5), and has no flag support whatsoever.

What happened was setsid was trying to parse the -w flag as a file name, resulting in execvp: No such file or directory error. Once I removed the flag, everything works. The end command now looks like:

env $BATCH_ENV setsid $BATCH_NAME $BATCH_OPTIONS >> $OUT_FILE 2>&1

Anything that now gets launched from “batch launcher” is assigned SID and PGID equal to PID of $BATCH_NAME, and kill calls on PGID of $BATCH_NAME leaves the “batch launcher” unaffected, which now happily reports return status 143 (SIGTERM).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement