how to make fifos keep data?

Martin Weitzel martin at mwtech.UUCP
Tue Jun 5 19:55:31 AEST 1990


In article <1038 at nixsin.UUCP> koerberm at nixsin.UUCP (Mathias Koerber) writes:
>Hello netlanders,
>
>I have a somewhat urgent problem on my hands, so could you please help me?
>
>I need to know if there is a possibilty to make named pipes (fifos) on
>Unix SysV keep their data, even when the reading process dies
                                          ^^^^^^^^^^^^^^^^^^^^ (first) 
>or the machine crashes.
        ^^^^^^^^^^^^^^^ (second)

The first is easy: Let some dummy process open the FIFO for read and write
and then sleep forever. The following C-program will do that, when given
the name of the FIFO as argument (you may want to add some error messages).

main(argc, argv) int argc; char **argv;
{
	if (argc > 1 && open(argv[1], 2) != -1) pause();
}

The second is rather impossible if you want to stay with FIFO-s -
at least if you want to protect against any kind of crash (eg. someone
hits the "RESET" of "BOOT" switch). If only "more or less controlled
rapid shutdowns" are your concern, you might extend the above daemon
so that it catches the respective signal (which is sent before the
machine goes down), sucks everything off the FIFO and writes to a
file. When restarted later, it should look for that emergency stop
file and re-feed to the FIFO.

-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.unix.questions mailing list