how to put a program into a .plan file

Paul John Falstad pfalstad at phoenix.Princeton.EDU
Thu Sep 27 14:42:57 AEST 1990


In article <1990Sep26.201406.12663 at athena.mit.edu> jik at athena.mit.edu (Jonathan I. Kamens) writes:
>In article <978 at bbt.UUCP>, rgs at bbt.UUCP (steinbeiser) writes:
>|> Ok, how do you check the status of the file to see if it has
>|> been open by someone else?  Its not obvious how (or if) stat() would do this.
>|> Also, would the C program have to be running constantly in the background
>|> someplace?
>2. Yes, it would have to be running constantly in the background someplace.

True.  (It's process wouldn't have to be RUNNING constantly, just present
constantly.)

>1. You open the pipe for write, and do a select() on it, and when you get an
>   OK to write from select(), you know that someone has opened the other end.
>
>I suppose another thing you could do would be to write a program that talks
>NFS, and mount it under your home directory (for kernels which support the use
>...

Ick.  Overkill, isn't it?

open()ing a FIFO for writing blocks until someone opens it for reading,
unless you have O_NDELAY set.  Try something like this with the Bourne shell
(I'm using SunOS 4.1):

/usr/etc/mknod foofo p
while true
do
date >foofo
done &

Now typing 'cat foofo' will print the date.  Each time the background subshell
tries to open the redirection file foofo, it will block until someone opens
it for reading.  So as soon as the open(2) call returns, you know
someone is accessing foofo.  As soon as the redirection file is opened,
the shell execs 'date', which pipes the date to whatever process is
catting foofo, and exits.

If Lafontaine's elk would spurn Tom Jones, the engine must be our head, the
dining car our esophagus, the guardsvan our left lung, the kettle truck our
shins, the first class compartment the piece of skin at the nape of the neck,
and the level crossing an electric elk called Simon.



More information about the Comp.unix.programmer mailing list