From owner-freebsd-questions Wed Sep 23 09:39:11 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id JAA26628 for freebsd-questions-outgoing; Wed, 23 Sep 1998 09:39:11 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from david.siemens.de (david.siemens.de [192.35.17.14]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id JAA26592 for ; Wed, 23 Sep 1998 09:39:02 -0700 (PDT) (envelope-from andre.albsmeier@mchp.siemens.de) X-Envelope-Sender-Is: andre.albsmeier@mchp.siemens.de (at relayer david.siemens.de) Received: from mail.siemens.de (salomon.siemens.de [139.23.33.13]) by david.siemens.de (8.9.1a/8.9.1) with ESMTP id SAA20261 for ; Wed, 23 Sep 1998 18:38:53 +0200 (MET DST) Received: from curry.mchp.siemens.de (daemon@curry.mchp.siemens.de [146.180.31.23]) by mail.siemens.de (8.9.1a/8.9.1) with ESMTP id SAA29600 for ; Wed, 23 Sep 1998 18:38:53 +0200 (MET DST) Received: (from daemon@localhost) by curry.mchp.siemens.de (8.8.8/8.8.8) id SAA29195 for ; Wed, 23 Sep 1998 18:38:53 +0200 (CEST) From: Andre Albsmeier Message-Id: <199809231638.SAA02576@internal> Subject: Re: How to get the PID before a program is run? (No joke :-) In-Reply-To: <19980923111119.A2733@emsphone.com> from Dan Nelson at "Sep 23, 98 11:11:19 am" To: dnelson@emsphone.com (Dan Nelson) Date: Wed, 23 Sep 1998 18:38:50 +0200 (CEST) Cc: andre.albsmeier@mchp.siemens.de, hamilton@pobox.com, freebsd-questions@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL40 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Transfer-Encoding: 7bit Content-Transfer-Encoding: 7bit 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. Yes, the thing with the two scripts appears to be the only way. Thanks a lot, -Andre To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message