Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!phoenix!pfalstad From: pfalstad@phoenix.Princeton.EDU (Paul John Falstad) Newsgroups: comp.unix.programmer Subject: Re: how to put a program into a .plan file Message-ID: <2859@idunno.Princeton.EDU> Date: 27 Sep 90 04:42:57 GMT References: <978@bbt.UUCP> <1990Sep26.201406.12663@athena.mit.edu> Sender: news@idunno.Princeton.EDU Organization: Princeton University, Princeton, New Jersey Lines: 41 In article <1990Sep26.201406.12663@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <978@bbt.UUCP>, rgs@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.