Interprocess Communication on UNIX SVR3
Leslie Mikesell
les at chinet.UUCP
Wed Apr 20 04:38:12 AEST 1988
In article <2592 at ihuxv.ATT.COM> bareta at ihuxv.ATT.COM (Benyukhis) writes:
>
>Can anyone outthere help me code the producer/consumer problem
>in "C". The prolog is as follows: the producer has to produce
>a char and deposit it in the shareable buffer for consumer to pick it up
>from. Both processes must use binary semaphores as a means of
>synchronization.
This sounds like you could use a pipe and avoid the need for any
semaphores. If this is a simple 1 to 1 arrangement, you can just
write producer to output to stdout, and consumer to read from stdin.
Then let the shell set up the pipe with "producer | consumer". Or,
one program can fork off a child process with a pipe connected (popen()
will do it all for you).
If you have multiple producers/one consumer or they cannot have the
same parent process, you can use a FIFO or named pipe (see mknod(1)
and mknod(2)).
Les Mikesell
More information about the Comp.unix.xenix
mailing list