how to put a program into a .plan file
Tony Rems
rembo at unisoft.UUCP
Sat Oct 6 08:36:32 AEST 1990
In article <1990Sep28.154733.26346 at cbnewsj.att.com> dwex at cbnewsj.att.com (david.e.wexelblat) writes:
>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?
>>
>> 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.
>>
>
>Or, in System V, quoting from the open(2) man page:
>
> When opening a FIFO with O_RDONLY or O_WRONLY set:
>
> If O_NDELAY is set:
> [ not relevant ]
>
> If O_NDELAY is clear:
> An open for reading-only will block until a process
> opens the file for writing. An open for writing-only
> will block until a process opens the file for reading.
>
>So all you have to do is make .plan a FIFO, and have a program open
>it for writing (the program will have to be in an infinite loop, though).
>
There are a bunch of ways to handle this in C. Doing a select is
really overkill. The simplest way is to have a loop that looks
something like:
make fifo;
loop forever;
open FIFO for writing /* This will block until
someon opens it for reading */
fork()
if in child:
exec a program
if in parent
close FIFO
wait for child;
I have a program called plan which takes one argument, the
name of a program to exec as your plan. This version inherits
your environment on the exec. If anyone would like a copy
of the source, drop me a note.
-Tony
More information about the Comp.unix.programmer
mailing list