Capturing a PID.

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Don Harrop
Date:  
Subject: Capturing a PID.
Thanks Tom, My original finding of jobs -l doesn't work because there is not associated tty. The command "jobs" just prints null. I think your $! will work though.. Thanks!

---------- Original Message ----------------------------------
From: Tom Bradford <>
Reply-To:
Date: Fri, 25 May 2001 11:02:11 -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.


Try this:

<your command> &
echo $! > program.pid

$! is the most recent program executed.
$$ is the current shell script

I've attached a copy of dbXML's startup script and its SYSV wrapper for
a better example.

--Tom

--
Tom Bradford --- The dbXML Project --- http://www.dbxml.org/
We store your XML data a hell of a lot better than /dev/null