Capturing a PID.

Eric Richardson plug-discuss@lists.PLUG.phoenix.az.us
Fri, 25 May 2001 11:27:58 -0700


Don Harrop wrote:
> 
> Does anyone have ideas on how to capture the pid of a program into a file as it starts up?  When you execute your program with the "&" (background process) the shell spits out the process id but I can't seem to redirect that out put to a file.  I don't want to use "pidof" after the fact either in case there is another process running with the same name.
> 
> Don
If you are in a shell script the current process is $$. The previous
backgroung job is $!.

echo $$ > sh.pid
foo&
echo $! > foo.pid

Hope this helps,
Eric R