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

In your script:

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

You can use $!. Referenced in the bash documentation.


You can use ps and grep to find the process in the process list and then awk to parse the output and find the actual PID:

ps -ef | grep -v grep | grep YOUR_PROCESS_NAME | awk '{ print $2 }'