[SunHELP] Script migration problems

David Eisner sunhelp at sunhelp.org
Thu Mar 29 10:04:46 CST 2001


On Thu, 29 Mar 2001, Dale Ghent wrote:

> On 29 Mar 2001, Ben Ricker wrote:
> 
> | I did as you suggested but still get the same problem. I have noticed
> | that every time, the PID written to the file is the JVM's real PID
> | subtract 3...a BIG kludge would be to take the PID and subtract 3 from
> | it. But that is not really a good idea.
> 
> Well, realistically, resolving "$$" by the shell itself will give you the
> shell's own PID.. not of any program it just kicked off. On the command

Right, if you don't use exec.  Using exec should cause the new program 
to be executed in place of the shell without creating a new process.

It seems to work for me.  Here's a simple program that writes
its pid and pauses:

    /* hw_pid.c */
    
    #include <stdio.h>
    #include <unistd.h>
    
    int
    main( int argc, char *argv[] ) {
    
        printf( "Hi.  My pid is %d\n", getpid());
        pause();
    }


And here's a bourne shell script (run_it.sh) to exec it:

    #!/bin/sh
    
    echo Shell PID is $$
    exec hw_pid

And on Solaris 7:

    venice[ ~...C/shtest ]% ./run_it.sh 
    Shell PID is 16725
    Hi.  My pid is 16725

Seems to work like you'd expect.

-David


-----------------------------------------------------
David Eisner            | E-mail: cradle at eng.umd.edu |
CALCE EPSC              | Phone:  301-405-5341       |
University of Maryland  | Fax:    301-314-9269       |
-----------------------------------------------------




More information about the SunHELP mailing list