I'm starting the same process multiple times and using the process ID to differentiate between them for future control. How would I go about getting back the process ID for the process I just started? Is it possible to append some sort of command to the command used to start the process?

link|improve this question
feedback

1 Answer

If you are using a Bash script, here's what you can do:

#!/bin/bash
gedit &
echo $! > /tmp/gedit.pid
sleep 5
kill -15 $(cat /tmp/gedit.pid)

This is just an example running gedit (text editor), saving its PID (Process ID) and killing it after 5 seconds using its PID and signal 15 (TERM).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.