signals to running processes
C Hudson Hendren III
hudson at vsedev.VSE.COM
Thu Dec 1 10:18:17 AEST 1988
In article <950 at taux01.UUCP> cjosta at taux01.UUCP (Jonathan Sweedler) writes:
>I have a program that takes a long time to finish running. From time
>to time (sometimes never, sometimes more frequently) I would like to
>find out the current status. The way I accomplish this is to send one
>of the user defined signals (SIGUSR1 - no. 30) to the process. The
>process has a signal handler that catches this signal and writes out
>the current state (number of loops done, how long it has been running,
>when it will finish, etc.). This all works fine but only I (the owner
>of the process) can send the signal. If my boss, for example, wants to
>look at the status of the process, he can't.
>
>I know I can have the program print out a status report every
>x minutes/hours/loops/whatever, but I don't want this. I want the
>report to be printed out only when specified to do so.
>
>Is there a cleaner approach?
If you are running under System 5, you can use the interprocess
communication facility. Have the program set up a message queue when it
starts. In order to talk to the program, you write another program which
opens the message queue and sends a message containing the tty number. You
make this inquire program setuid to the uid of the running program since it
will want to send a SIGUSR1 signal to the program. The running program
catches the signal and looks to see what is waiting in the message queue.
Upon finding the tty number of the requestor, it writes a message upon that
console. As an alternative, you can have the running program send its
status back through the message queue (thismakes it easier if you are in the
habit of having unwritable ttys).
You will certainly want to RTFM for more information on how to do this.
Once you get in the habit of using the SVID IPC facility, you will find
numerous uses such as this.
--
==> ..!uunet!vsedev!hudson [hudson at vsedev.vse.com] (C Hudson Hendren III) <==
==> These are my opinions and are not necessarily those of VSE Corporation. <==
==> MS-DOS was created to keep idiots away from UNIX computers <==
More information about the Comp.unix.questions
mailing list