HP3000-L Archives

December 2000, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Danny A. van Delft" <[log in to unmask]>
Reply To:
Danny A. van Delft
Date:
Fri, 8 Dec 2000 02:46:32 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (28 lines)
On Tue, 5 Dec 2000 14:01:18 -0600 (Central Standard Time), Mark Bixby
<[log in to unmask]> wrote:

<snip>

>It would also normally be an exercise for the reader to use the shell to obtain
>pids without using ps for things that don't write their pids to disk files, but
>since I have some time today to explain, here's the magic shell incantation:
>
>        serverprogram serverparms &; echo $! >/tmp/server.pid; wait
>
>You invoke the server program and pass any expected parameters, then follow the
>last parameter (if any) with an ampersand (&).  The ampersand tells the shell
>to run the command asynchronously, kind of like MPEX ;GOON (IIRC).  The $!
>variable contains the pid of the last asynchronous command, so we echo it to a
>disk file suitable for later killing, i.e. kill `cat /tmp/server.pid`.  Lastly,

A problem with this approach is that if "serverprogram" is already
running, you've now zapped its pid in the pid-file and made it
un-killable by the "`cat pid-file` technique.
For that reason I've written a small (perl, but that's not the point)
program that uses a semaphore file to prevent "serverprogram"
(supplied as 1st argument to this program) from being invoked more
than once. Or, better, when you're writing you're own highlander type
program, include the pid writing stuff in the program itself.

Danny A. van Delft   [log in to unmask]

ATOM RSS1 RSS2