From owner-freebsd-questions Wed Sep 23 09:12:57 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id JAA21200 for freebsd-questions-outgoing; Wed, 23 Sep 1998 09:12:57 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id JAA21190 for ; Wed, 23 Sep 1998 09:12:53 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.9.1/8.9.1) id LAA03449; Wed, 23 Sep 1998 11:11:19 -0500 (CDT) Date: Wed, 23 Sep 1998 11:11:19 -0500 From: Dan Nelson To: Andre Albsmeier , Jon Hamilton Cc: freebsd-questions@FreeBSD.ORG Subject: Re: How to get the PID before a program is run? (No joke :-) Message-ID: <19980923111119.A2733@emsphone.com> References: <199809231352.PAA05460@david.siemens.de> <199809231400.QAA00941@internal> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.94.3i In-Reply-To: <199809231400.QAA00941@internal>; from "Andre Albsmeier" on Wed Sep 23 16:00:18 GMT 1998 X-OS: FreeBSD 2.2.7-STABLE Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In the last episode (Sep 23), Andre Albsmeier said: > someone wrote: > > In message <199809230729.JAA12131@internal>, Andre Albsmeier wrote: > > } I want to start a program but I need its PID before it is run. > > } One way would be to load the program and send a -STOP signal very > > } quickly. Then I have got the PID, can do some things and send a > > } -CONT signal when finished. > > > > It's actually fairly simple, though somewhat off the beaten path. > > Something like: > > > > #!/bin/sh > > echo "PID is $$" > > exec /your/program/here > > OK, this replaces my shell script. But I have to do some stuff later > when /your/program/here is finished. Well, you could call that script from _another_ script :) You should be able to do this in one shell script, like this: #! /bin/sh ( echo $$ > /var/run/prog.pid echo 'program starting with pid $$' exec /bin/prog ) echo 'program finished' ,but according to the sh manpage, subshells keep $$ at the original shell's pid, so $$ in the above script has the wrong pid. You'll have to split it into two scripts. -Dan To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message