sending signals upstream

B

bill

This is not strictly a C question, but groups such as comp.unix.wizards
seem to have died. Does anyone know the appropriate group for this
question?

I want to signal an upstream process. eg:
% a | b | c | d
and d wants to send a signal to a.
The problem is: how does d get a's pid. I see 4 solutions:


1) a writes its pid information into the pipe.
drawback) intermediate processes need to deal with it. This
makes it difficult to use them arbitrarily as the start of the pipe
as now:
% cat foo | b | c
is problematic. A simple solution for this
is to take a command line arg to indicate start of pipe: eg
% cat foo | b -s | c...

2) a writes its pid on stderr and I do something ugly like:
% ( a | b | c ) 2>&1 | d
drawback) ugly as sin, difficult to handle multiple upstream
data paths, and I lose stderr. (I could use fd 3 instead, eg "3>&1",
but this is going to get real ugly, real fast.)

3) a registers its pid in a pid file. eg /var/run/a.xxx where
xxx is the gid. This is pretty decent, but there are some
naming conflicts in a pipe that looks like
% a | b | c| d | a | b | c | d
as both instances of a have the same gid.
In all the instances I can think of at the moment, d will want
to signal the process that is closest to it in the pipe, so it
can parse the pid file and pick the one with the pid closest
to its own, but this is inherently inflexible. It also relies on the
pids being assigned montonically
(ie d > c > b > a), and I'm not sure that's reliable.

4) Write a controlling process that catches the signals and
farms them out appropriately. Unfortunately, I think that this
and solution 1 are the only things that will really work. But
writing the parent means I completely lose the ability to
simply enter commands at the shell prompt, and I really
want that. I can't see a good way to write it as a
shell script, as if we include the line:
a | b | c | d &
in the script, I don't know how to get a's pid.

I'm hoping someone can give me solution number 5...
 
W

Walter Roberson

This is not strictly a C question, but groups such as comp.unix.wizards
seem to have died. Does anyone know the appropriate group for this
question?
comp.unix.programming


I want to signal an upstream process. eg:
% a | b | c | d
and d wants to send a signal to a.
The problem is: how does d get a's pid. I see 4 solutions:

[OT]

process groups
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top