r/smallprog • • Mar 16 '10

[bash] Remember the pid of a process.

Use $! to get the process id of the last process run in the background.

For instance, remember the pid:

sleep 10000 &
echo $! > pid.txt

And kill the process later:

kill -9 `cat pid.txt`

Edit: Added clarification about background.

5 Upvotes

6 comments sorted by