Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

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).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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