SUMMARY: how to capture PID at execution time

From: Dan's generic account (ocalld_at_eads.com)
Date: 03/30/05

  • Next message: joe biggs: "Script for Printer"
    To: "Sunmanagers LIST" <sunmanagers@sunmanagers.org>
    Date: Wed, 30 Mar 2005 19:58:48 +0100
    
    

    Thanks to all those that replied.

    The answer is:

    $! returns pid of last background process
    $$ returns current process pid.

    The "gotcha" i had was that my script executes more scripts to run the httpd.
    I couldn't capture the pid of commands in sub-scripts.

    I found that by obtaining the pid of the master script when started
    "echo $$ > /var/run/master.script.pid" (declared at begging of script)
    i could use this group pid to kill all processes started by the main script with:
    pkill -g `cat /var/run/master.script.pid`

    Thanks
    Dan.

    On Tue, 2005-03-29 at 20:24, Dan's generic account wrote:
    > Hi all
    >
    >
    > Is it possible to capture the PID of a command at the time of execution and
    > write it to a log file???
    >
    > I need to capture the PID at the time of execution, as several instances of
    > the command will be run at the same time, i need to make sure that the correct
    > process is killed when required.
    >
    > an example would be having several instances httpd running.
    >
    > running the httpd startup script produces the following output:
    > ./scripts/httpd.sh 2>&1 |tee /var/log/jini.httpd.log &
    > [1] 1199
    > bash-2.03# Mar 29, 2005 8:28:05 PM com.sun.jini.tool.ClassServer run
    > INFO: ClassServer started [lib/dl/, port 8082]
    >
    >
    >
    >
    > the 1199 is the group process, so i could just use "kill -- -1199". any child
    > process die.
    > The above pipe to tee does not report the group PID. i just get the
    > following:
    >
    > bash-2.03# cat /var/log/jini.httpd.log
    > Mar 29, 2005 8:28:05 PM com.sun.jini.tool.ClassServer run
    > INFO: ClassServer started [lib/dl/, port 8082]
    >
    > how can i trap the PID?
    >
    > Thanks
    > Dan.
    >
    >
    > The information contained within this e-mail and any files attached to this
    > e-mail is confidential and in addition may include commercially sensitive
    > information. The contents of this e-mail are for the intended recipient only
    > and therefore if you wish to disclose the information contained within this
    > e-mail or attached files, please contact the sender prior to any such
    > disclosure.
    > If you are not the intended recipient, any disclosure, copying or distribution
    > is prohibited. Please also contact the sender and inform them of the error and
    > delete the e-mail, including any attached files from your system.
    > _______________________________________________
    > sunmanagers mailing list
    > sunmanagers@sunmanagers.org
    > http://www.sunmanagers.org/mailman/listinfo/sunmanagers
    _______________________________________________
    sunmanagers mailing list
    sunmanagers@sunmanagers.org
    http://www.sunmanagers.org/mailman/listinfo/sunmanagers


  • Next message: joe biggs: "Script for Printer"

    Relevant Pages

    • Re: LTT user input
      ... and to that end have taken the existing trace infrastructure ... script for that event (if there's a handler defined for the event ... This gives the script a chance to do whatever Perlish thing it ... syscall totals to individual syscall totals for each pid. ...
      (Linux-Kernel)
    • how to capture PID at execution time
      ... Is it possible to capture the PID of a command at the time of execution and ... the command will be run at the same time, i need to make sure that the correct ...
      (SunManagers)
    • piped system commands
      ... I want to run a command inside a script. ... From the shell, here's the command: ... What is returned is the pid of the process being grep'd. ...
      (perl.beginners)
    • Re: Fwd: Any way to find the network usage by a process?
      ... Here's a variation of Jose's script that uses the networking tapset and prints top-like output for transmits and receives. ... Much of the activity shows up under pid 0, ... Can anyone suggest better probe points to get transmits and receives by pid? ... execname[pid()] = execname ...
      (Linux-Kernel)
    • [SLE] pidof in loop
      ... application in a script. ... One of the solutions given was the command ... $i will be 'pidof spamd', ... does not contain the pid of spamd. ...
      (SuSE)