Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #162349

Re: How can a daemon process open() the stdout of someone who signals it?

From John Forkosh <forkosh@panix.com>
Newsgroups comp.lang.c
Subject Re: How can a daemon process open() the stdout of someone who signals it?
Date 2021-08-12 03:17 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <sf23rs$jle$2@reader1.panix.com> (permalink)
References <sf0kp8$ki0$1@reader1.panix.com> <20210811110000.589@kylheku.com>

Show all headers | View raw


Kaz Kylheku <563-365-8930@kylheku.com> wrote:
> John Forkosh <forkosh@panix.com> wrote:
>> Specifically, below's the little test program I wrote.
>> It works fine, but isn't programmed to do exactly what I want
>> because I can't figure out how to program that.
>>
>> It runs as a daemon, just sitting on a pause() until
>> it catches a signal, via  killall -SIGINT testdaemon
>> and then it just writes a dummy line with date/time and
>> #running processes to a log file. Just a "Hello, World" test.
>>
>> But what I want is to write some stuff to the stdout
>> of the process that sent the signal to testdaemon.
> 
> I wouldn't bang my head against the wall by doing it this way.
> 
> What you can do is implement a little management protocol for
> your server that uses some inter-process communication mechanism,
> like sockets.
> 
> Then write a CLI over the protocol that provides a command language
> for doing things with the server.
> 
> The server can send output over the protocol, which the CLI can dump on
> its standard output.
> 
> There are things you can try. In Unix, there are ways to send an open
> file descriptor from one process to another. So it seems like it would
> be possible to connect to the server somehow, and say "here is file
> descriptor; please send printed output to it" (it happens to be my
> standard output).
> 
> Open descriptors can be passed over Unix sockets (AF_UNIX == AF_LOCAL
> address family) and SystemV streams and maybe other ways.
> 
> I don't think signal handling can pass an open descriptor, so it
> couldn't literally work they way you want: get a signal from
> some process, and then obtain a descriptor from it.
> 
> More like, process opens an AF_UNIX socket to the server,
> and passes the desired file descriptor.

Thanks for the suggestions, Kaz. Sockets sounds like the easiest
and most straightforward approach, so I'll be checking that out
more carefully first.
-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

Back to comp.lang.c | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How can a daemon process open() the stdout of someone who signals it? John Forkosh <forkosh@panix.com> - 2021-08-11 13:53 +0000
  Re: How can a daemon process open() the stdout of someone who signals it? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-11 15:41 +0000
    Re: How can a daemon process open() the stdout of someone who signals it? John Forkosh <forkosh@panix.com> - 2021-08-12 03:11 +0000
    Re: How can a daemon process open() the stdout of someone who signals it? Vir Campestris <vir.campestris@invalid.invalid> - 2021-08-13 21:30 +0100
      Re: How can a daemon process open() the stdout of someone who signals it? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-14 14:25 +0000
  Re: How can a daemon process open() the stdout of someone who signals it? Kaz Kylheku <563-365-8930@kylheku.com> - 2021-08-11 18:10 +0000
    Re: How can a daemon process open() the stdout of someone who signals it? John Forkosh <forkosh@panix.com> - 2021-08-12 03:17 +0000

csiph-web