How could I write a Bash-script that runs a long running program and stores the programs process id in a separate file?
I want something like
#!/bin/bash
exec long_running_tool
echo `ps af |grep "long_running_tool" |awk '$5 == "long_running_tool" {print $1}'` > pid_file
However doing exactly this would execute the ps
after tool has finished.
Is there a way to get the process id of the process created?
long_running_tool
process. Consequently, exec never returns and the following line is never reached. Seehelp exec
,execve(2)
.