[comp.unix.questions] Question on interprocess communication and signals

reiner@jabberwock.shs.ohio-state.edu (Reiner Wilhelms) (08/30/90)

Question 1. 
----------
In signal.h are two signals defined:
#define SIGUSR1 30      /* user defined signal 1 */
#define SIGUSR2 31      /* user defined signal 2 */

How can they be generated?  (In the man pages I couldn't find a hint
to this.) Does this relate to the following problem, and to question 2?

The Problem:
------------
 I have one program, call it B, which reads a file of
vectors, displays them on the screen, and then enters an interactive
mode in which it is possible to perform geometric transformations of
the data - rotation, scaling etc.  As the program was designed for
SunView, it enters the SunView subroutine window_main_loop() after
building up a control panel and reading the data for display. It
remains in the window_main_loop until it exits. To make this program
read the next file for display, one could for example define a special
button which, when pressed, results in calling a subroutine to read
the file.  
Now I am writing another interactive program, call it A, which
generates the data for B.

Question 2: 
----------- 

How can one build a communication line between the two such that A
dials B, and says: "Hey, I have a new data set for you!" Essentially
program A "presses the read-new-data button" of program B.  What would
the notification routine look like, and what kind of signals could I
use to establish the cooperation of the two programs?

Any suggestions are highly appreciated. 

Reiner

cpcahil@virtech.uucp (Conor P. Cahill) (08/30/90)

In article <265@jabberwock.shs.ohio-state.edu> reiner@jabberwock.shs.ohio-state.edu (Reiner Wilhelms) writes:
>In signal.h are two signals defined:
>#define SIGUSR1 30      /* user defined signal 1 */
>#define SIGUSR2 31      /* user defined signal 2 */
>
>How can they be generated?  (In the man pages I couldn't find a hint
>to this.) Does this relate to the following problem, and to question 2?

They are generated with the following system call:

	kill(pid,SIGUSR1) or kill(pid,SIGUSR2)


>How can one build a communication line between the two such that A
>dials B, and says: "Hey, I have a new data set for you!" Essentially
>program A "presses the read-new-data button" of program B.  What would
>the notification routine look like, and what kind of signals could I
>use to establish the cooperation of the two programs?

You could do zillions of different things.  Like each time through the
loop in B, it checks for a new data file in a given directory.  Or 
process A could send a signal to process B.  Or process A could send
the data in a message queue to process B, etc, etc, etc...
-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

les@chinet.chi.il.us (Leslie Mikesell) (08/30/90)

In article <265@jabberwock.shs.ohio-state.edu> reiner@jabberwock.shs.ohio-state.edu (Reiner Wilhelms) writes:

>Question 2: 
>How can one build a communication line between the two such that A
>dials B, and says: "Hey, I have a new data set for you!" Essentially
>program A "presses the read-new-data button" of program B.  What would
>the notification routine look like, and what kind of signals could I
>use to establish the cooperation of the two programs?

You probably have select() which can block while waiting for any of
several inputs, but since I'm stuck with SysV for the moment, my
favorite technique is to funnel all inputs through a single pipe
(or FIFO where it is inconvienent to make all processes have a common
parent).  In your case, the screen-drawing program might read all
its commands from a pipe fed by both the keyboard-reading process
and the data-generating process.  There are some tricks to make it
work, though.  The commands must either be of a fixed length or
contain a length field so that the reader can seperate them at
the original boundaries, and the complete command must be written
in a single write() and must be less than PIPE_MAX in size to
avoid interleaving with data from a different process.

Les Mikesell
  les@chinet.chi.il.us