HP3000-L Archives

December 2000, Week 1

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:
Mark Bixby <[log in to unmask]>
Reply To:
Mark Bixby <[log in to unmask]>
Date:
Tue, 5 Dec 2000 11:40:46 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (59 lines)
Donna Garverick wrote:
>
> several people have asked:
>
> > What is ps?
>
> oh...well....ok....  i'd compare ps to showjob.

:SHOWJOB is close, but I'd actually compare it to :SHOWPROC.

> using 'kill', i've come to understand, applies to all (is that
> right, mark?) these wonderful new posix background 'things' on
> our systems.  things include: syslog, sendmail, bind,
> samba....  i guess most of these s/w packages 'know' what to do
> when they're killed (btw, could they have picked a worse name
> for this command?).  that is, they do a 'gracefullish'
> shutdown.  to them, abortjob is like a big, heavy sledge
> hammer.

Saying that "all" opensource Internet servers support intelligent use of kill
may be a bit strong.  But I think that most of the services you list do support
kill in order to do a graceful shutdown.

> kill needs a 'pid' (a process id) to do it's thing.  how do you
> get a pid?  by using ps.  (ohhh, ahhh :-).  the problem is, ps
> (on 6.0) was compiled without 'ba' capability -- makes it kinda
> hard to write a *job* to halt posix jobs....
>
> btw, since mark is busy (:-) i'll add that for apache in
> particular, the designers had the sense to write the pid out to
> a file (duh), so you don't have to figure it out.  my httpstop
> job (which has all of 3 lines in it :-) has the following
> command:
>
> !xeq sh.hpbin.sys "-c 'kill `cat logs/httpd.pid`'"
>
> (it's an exercise for the reader to figure out the other 2
> lines :-)         hth      - d

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,
the wait command tells the shell to wait for all child process to finish, i.e.
the asynchronous command.

By using this technique and modifying the server batch job to launch the
service via the shell instead of a direct :RUN, you can capture the pid without
needing to use ps.

- Mark B.

ATOM RSS1 RSS2