I need to set a trap for a bash process that I am starting in the background. The background process can take a very long time and contain the PID in a specific file.
Now I need to set a trap for this process, so if it ends, the PID file will be deleted.
Is there a way I can do this?
EDIT # 1
It looks like I was not accurate enough with my description of the problem. I have full control over all the code, but I have a lengthy background process:
cat /dev/random >> myfile&
When I now add a trap at the beginning of the script, this statement is in $$ , it will be the PID of this larger script of this small background process, which I start here.
So how can I set up traps for this background process?
source share