[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

a parrot for storing state

Here is a simpler "parrot" program that stores a string
(second arg) that can be read once from the fifo named
in the first arg.  The parrot, spawned by the program
that wants to store its state, lives until the given
string is read out of the fifo by the next instance of
the program.  Now, will this work if the fifo is on a
ro filesystem?

$ mkfifo foo
$ ls -l foo
prw-r--r--    1 jdthood  jdthood         0 2003-03-14 12:35 foo|
$ ./parrot foo yadda &
[1] 10924
$ cat foo
[1]+  Exit 1                  ./parrot foo yadda

Here's the program:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

main(int argc, char * argv[])
	int fd;

	if (argc < 3)

	fd = open( argv[1], O_WRONLY );
	if (!fd)

	write(fd, argv[2], strlen(argv[2]));
	write(fd, "\n", 1);

Thomas Hood <jdthood0@yahoo.co.uk>

Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts

Reply to: