PDA

View Full Version : Just a quick shell question...



caro23
14th June 2008, 11:23 AM
Hi,

I have a small question concerning a shell script.
How can i find out the process id of a programm i've started in a shell script?

Something like this?
$pid = ....

Thanks in advance,
Caro

daneel971
14th June 2008, 12:31 PM
you can use pidof

bwire66
14th June 2008, 01:28 PM
One way to do it:


pid=$(ps -C <programm> -o pid=)

caro23
14th June 2008, 01:55 PM
Well, the problem is, those commands search for a specific name. However, i have started the program multiple times...

bingoUV
14th June 2008, 02:02 PM
In the following line, write


pid=$!


For example, if you start e.g. emacs in the background from a script, $! will give the pid of that instance of emacs which you started just above.

duncan
14th June 2008, 02:08 PM
try:
pid=$$;
echo $pid

bwire66
14th June 2008, 02:33 PM
Well, the problem is, those commands search for a specific name. However, i have started the program multiple times...
Why don't you try providing a complete description of your problem instead of leaving it to us to fill in the blanks?

caro23
14th June 2008, 03:39 PM
Ok, thanks!

pid=$! solved my problem!