mchetan@hawk.ulowell.edu (Munisuvratha Chetan) (11/28/90)
Hi, I have a problem with "pipe"s, which might have appeared earlier. I have two processes - a server and a client. The server runs in an infinite loop untill killed. After the server is brought up, clients wil be forked, from a different shell. If the clients know the process id of the server, how can I establish a communication channel between the two using pipes (and signals, if necessary) only. I know how to create pipes between a parent and child. Any help is greatly appreciated. Thanx a bunch.
les@chinet.chi.il.us (Leslie Mikesell) (12/04/90)
In article <1510@ulowell.ulowell.edu> mchetan@hawk.ulowell.edu (Munisuvratha Chetan) writes: >I have a problem with "pipe"s, which might have appeared earlier. >I have two processes - a server and a client. >The server runs in an infinite loop untill killed. >After the server is brought up, clients wil be forked, from a >different shell. If the clients know the process id of the >server, how can I establish a communication channel between the >two using pipes (and signals, if necessary) only. >I know how to create pipes between a parent and child. If your system supports FIFOs (named pipes) just let the server create on using a name known to the clients. All clients can write to the single FIFO read by the server (with some care to keep things that must not be interleaved in a single write()), and this will automatically schedule the requests. Communicating back to the client is a different problem. Depending on the circumstances, you might want the client to create a FIFO as well and pass its name in the request to the server, or you might use shared memory or ordinary files with the server sending a signal to the client when the output is completed and safe to read. (See the man page for mknod to find out if you have named pipes.) Les Mikesell les@chinet.chi.il.us
roger@gtisqr.uucp (Roger Droz) (12/06/90)
In article <1510@ulowell.ulowell.edu> mchetan@hawk.ulowell.edu (Munisuvratha Chetan) writes: > >I have two processes - a server and a client. >The server runs in an infinite loop untill killed. >After the server is brought up, clients wil be forked, from a >different shell. If the clients know the process id of the >server, how can I establish a communication channel between the >two using pipes (and signals, if necessary) only. How about using named pipes. (See mknod(1)) The server can open(2) several named pipes with O_NDELAY set and start polling. The clients don't need to know the process id of the server; just the directory where the set of named pipes can be found. The clients can tell when they open a pipe for writing if a reader (the server) is running. You will need to come up with some mechanism of lock files to keep two clients from opening the same pipe. You will also need two pipes for each client to accomplish two way communication, but I assume you already know that. There are other ways of doing this sort of thing in Unix, but you said you wanted to use pipes. ____________ Roger Droz UUCP: uw-beaver!gtisqr!roger () () Maverick MICRoSystems / Global Technology International (_______) Mukilteo, WA ( ) | | Disclaimer: "We're all mavericks here: | | Each of us has our own opinions, (___) and the company has yet different ones!"
les@chinet.chi.il.us (Leslie Mikesell) (12/07/90)
In article <1990Dec5.225853.1370@gtisqr.uucp> roger@gtisqr.uucp (Roger Droz) writes: >The server can open(2) several named pipes with O_NDELAY set and start >polling. >You will need to come up with some mechanism of lock files to keep two >clients from opening the same pipe. On the contrary - the server can accept all input from a single pipe and not have to bother with O_NDELAY or polling. The constraint to this method is that a logical request from a client (i.e. the chunk of data that can't be interleaved with requests from other clients) must be less than PIPE_BUF (typically 5120) bytes and delivered in a single write(). Also, all writes() must use a pre-arranged fixed length, a length count as the first field, or a delimiter of some sort to allow the server to find the boundaries. A server running in this mode would generally open the FIFO for write access itself even though it will never write to it in order to make the reads block until a client completes a write(). >You will also need two pipes for each >client to accomplish two way communication, but I assume you already know >that. The client still needs one pipe of its own for communication in the other direction. Les Mikesell les@chinet.chi.il.us