Re: get PID for a process

From: Ed Morton (mortonAVOIDINGSPAM_at_Lucent.com)
Date: 08/07/03


Date: Thu, 07 Aug 2003 09:22:17 -0500


On 8/7/2003 5:28 AM, Willem Kossen wrote:
> "stephan beal" wrote in message
>
>
>>>I want my startup script to make a pid file for a process that does not
>>
> do
>
>>>so itself. How can i get the pid of the proces i just started?
>>
>>The $! variable holds the PID of the last-run app:
>>
>>stephan@cheyenne:~/> emacs &
>>[1] 20743
>>stephan@cheyenne:~/> echo $!
>>20743
>
>
> I know, but it doesn't seem to work from a shell-script and I'm not using &
> is there another way?

It does work from a shell script, but only for background processes. You could
do a "ps" and pipe it to grep or awk for your command name - post a version of
the script if you want better suggestions.

        Ed.



Relevant Pages

  • csh shell script situation
    ... execution of script doesnt complete ... I've included shell script below: ... setenv PIPE $home/trainrefresh/trainrefresh_ora.dmp ... In essence I'm trying to dump file content into pipe then have Oracle ...
    (comp.unix.shell)
  • Re: named pipes versus the unnamed pipeline using "|"
    ... >We have a shell script which does something like this: ... > mkfifo $pipe ... current command and begins the next command. ...
    (comp.unix.shell)
  • Re: Piping into a shell script
    ... > I want to write a shell script in bash, where I can pipe other commands ...
    (comp.os.linux.misc)
  • Re: stdout buffer in pipe filled up
    ... > CT> My program creates a pipe and then forks to create a child. ... > CT> The child reads from a shell script and puts it to the stdout and the ... > CT> is more than 9K, the waitid() is hanging, waiting for the child to ...
    (comp.unix.programmer)
  • Re: Problem in Running a Tool on Wish Console
    ... a my previously written Shell script to Tcl driving ModelSim. ... interpreter is unable to recognize the "echo" key word. ... thats why the pipe operator is used in shell script. ... puts $pipe "run -all" ...
    (comp.lang.tcl)