Friday, July 22, 2005

exec overlays the running process with the new program - the PID is maintained.

> #!/bin/sh
> echo $$ > .pidlog
> exec myprogram
> Tried this, but $$ is the pid of the script itself and not the program
> being run. Subsequent kill on $$ result doesn't stop myprogram.

I just tried this on Solaris 2.6/x86 (sorry, I haven't got access to a
SPARC version any longer):

Sun Microsystems Inc. SunOS 5.6 Generic August 1997
$ echo $$
344
$ exec ksh
$ echo $$
344
$ ps
PID TTY TIME CMD
344 pts/0 0:00 ksh
$

As you can see, the exec overlays the running process with the new
program - the PID is maintained. Thus, the solution proposed by Icarus
will work because as long as your "myprogram" isn't itself the result of
a fork, the .pidlog file will contain the PID of the exec'd program.

Are you sure you used "exec"?

0 Comments:

Post a Comment

<< Home