System Administration & Network Administration
linux command-line-interface daemon nohup
Updated Thu, 07 Jul 2022 17:12:59 GMT

How do I find out the process id of the backgrounded process?


I've got a command (program) that I'd like to run with nohup and background it. Like

nohup command > logfile.txt &

How do I find out the process ID? I would like to be able to write the process id in a file, read it later and kill the process programatically.




Solution

In your script:

nohup command > logfile.txt &
echo $! > /var/run/command.pid