Getting PID of spawned processes from a KShell

Getting PID of spawned processes from a KShell

Post by Brian Flemin » Wed, 25 Aug 1999 04:00:00



I'm working with a korn shell script.  What I would like to do is be
able to execute commands on a remote machines like this:

rsh $machine_name ${some_script} &

What I want is the PID of this child process, but I can't figure out how
to get it from inside my shell script.  When you use the & at the
terminal the pid is displayed for you.  I wanted to somehow capture
that.  This way if I need to terminate that process from within my shell
script I can, because I'll have the pid.

Thanks for any input.  I was searching deja news but their database is
completed messed up.

 
 
 

Getting PID of spawned processes from a KShell

Post by Dan Merc » Wed, 25 Aug 1999 04:00:00




> I'm working with a korn shell script.  What I would like to do is be
> able to execute commands on a remote machines like this:

> rsh $machine_name ${some_script} &

> What I want is the PID of this child process, but I can't figure out how
> to get it from inside my shell script.  When you use the & at the
> terminal the pid is displayed for you.  I wanted to somehow capture
> that.  This way if I need to terminate that process from within my shell
> script I can, because I'll have the pid.

> Thanks for any input.  I was searching deja news but their database is
> completed messed up.

Use a co-process:

   rsh $machine_name /usr/bin/ksh |&
   print -p "${some_script} &"
   print -p "print $!"
   read -p rempid

This is obviously a very stripped down version to get you started.
You'll want to add error checking,  etc. to make it more robust.

--
Dan Mercer


 
 
 

Getting PID of spawned processes from a KShell

Post by Rainer Temm » Thu, 26 Aug 1999 04:00:00



> I'm working with a korn shell script.  What I would like to do is be
> able to execute commands on a remote machines like this:

> rsh $machine_name ${some_script} &

> What I want is the PID of this child process, but I can't figure out how
> to get it from inside my shell script.  When you use the & at the
> terminal the pid is displayed for you.  I wanted to somehow capture
> that.  This way if I need to terminate that process from within my shell
> script I can, because I'll have the pid.

Hi Brian,
...
the pid of the last background process started by your shell is stored in
the variable $! ...
try ...
sleep 1000 &
echo $!
...
Regards Rainer
 
 
 

Getting PID of spawned processes from a KShell

Post by Ming G » Thu, 26 Aug 1999 04:00:00





> > I'm working with a korn shell script.  What I would like to do is be
> > able to execute commands on a remote machines like this:

> > rsh $machine_name ${some_script} &

> > What I want is the PID of this child process, but I can't figure out how
> > to get it from inside my shell script.  When you use the & at the
> > terminal the pid is displayed for you.  I wanted to somehow capture
> > that.  This way if I need to terminate that process from within my shell
> > script I can, because I'll have the pid.

> > Thanks for any input.  I was searching deja news but their database is
> > completed messed up.

> Use a co-process:

>    rsh $machine_name /usr/bin/ksh |&
>    print -p "${some_script} &"
>    print -p "print $!"
>    read -p rempid

> This is obviously a very stripped down version to get you started.
> You'll want to add error checking,  etc. to make it more robust.

> --
> Dan Mercer


  dan -- could you please explain the code in more detail?  thanks.
ming
 
 
 

Getting PID of spawned processes from a KShell

Post by vega.. » Sat, 18 Sep 1999 04:00:00


Rainer, or anyone who can answer:
Your post was in regaurds to a korn shell.  I have tried this using a
csh, with no success.  Is there a way to get the pid of the last
background process started by a csh?




> > I'm working with a korn shell script.  What I would like to do is be
> > able to execute commands on a remote machines like this:

> > rsh $machine_name ${some_script} &

> > What I want is the PID of this child process, but I can't figure
out how
> > to get it from inside my shell script.  When you use the & at the
> > terminal the pid is displayed for you.  I wanted to somehow capture
> > that.  This way if I need to terminate that process from within my
shell
> > script I can, because I'll have the pid.

> Hi Brian,
> ...
> the pid of the last background process started by your shell is
stored in
> the variable $! ...
> try ...
> sleep 1000 &
> echo $!
> ...
> Regards Rainer

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
 
 
 

1. How to get PID of a child/spawned process?

Hello -

I have a program that currently uses a system() call to spawn an external
program (GNUPlot).  Is there a quick and easy way to find the PID of the
spawned process?

Thanks in advance,

(ps - could replies be sent via email as well? ...trouble with USENET here.)

--
Christopher Curtis, Sun SysAdmin - http://www.ee.fit.edu/users/ccurtis
Florida Institute of Technology  - telnet bofh.engr.wisc.edu 666
Melbourne, Florida  USA          - Member, Team OS/2

2. ICMP redirection!?

3. Getting error "couldn't spawn child process: "

4. buffer problem

5. getting process pid

6. Help: NEC MO Drive

7. Getting PID of background process

8. smail3 daemon TCP/IP problems

9. Getting children's PID with parent's pid?

10. Getting PID of a process using ps aux, grep and ???

11. Getting PID of background process in shell script.

12. Getting PID at process start up time

13. getting process's pid in a script