How do I determine the last background process id in a bash shell script?
-
Man page for bash - GNU Bourne-Again SHell
Run any command in the background.
$ uptime & [1] 2336 $ 09:26:57 up 6 min, 12 user, load average: 0.01, 0.23, 0.16 [1]+ Done uptime
Check the process id of the last background command.
$ echo $! 2336
In scripts this can be useful for passing the process id to other commands, finding out status, statistics and sending signals to the process id.
© Lightnetics 2024