IPC - pipes between parent and child process

Hi guys, I'm having some problem here, I'm studying pipes, and i want to create a shell in C and at this point a don't want to use semaphores, instead I want to use tricks. Straight to the doubt: I've a parent and a child process, and both of them has some code to execute, and the child process code need the data on the file descriptor which is written by the parent process, my problem is i can't make the child process to execute the code after the parent process writes the data on the file descriptor.

Thanks

PS: I don't want to use semaphores yet.

Subroutine popen() is the easiest way to create a child and send it a stream. Otherwise pipe, fork, close, fdup, and if desired, exec*(). Oh, fflush() if using FILE*.!

I've been awared of that, but my goal is to learn how to synchronize read/write file descriptors without using semaphores, my professor said that is possible and told us o theorical pseudo-code.

Using for instance a pipe between the parent and the child (write end at the parent, read end at the child), you may synchronize as follows: the child waits (i.e. reads the pipe using a blocking read) until the parent tells the child to go ahead (by writing something into the pipe). You ensure that the child will only execute once the parent told to do so.

If you need to synchronize the other way around (parent waits - child tells), use a pipe in the other direction (write end at the child, read end at the parent). And if you need to synchronize in both directions, you will need two pipes.

HTH,
Lo�c

Well, it sounds like you need a protocol, or operate your pipes full duplex with at state machine at each end to take care of activities on that overlaid protocol. Decoding & analyzing professors is much more complex than decoding & analyzing an API. :smiley:

If you find pipes, sockets, shmem, semaphores, queues and all that a bit restrictive, you can mmap() a file in both processes, creating an area of shared memory, not to be confused with the silly UNIX ipc shared memory that needs root setup and such dusty old stuff, and the nice thing is that you can peek at the mmap90'd file during or after for you edification about what is going on. It is really fast, RAM write snoop invalidating cache fast. You can even have a file for each writer, so there is no ambiguity about who put the file in that state.

If you are using pipe between the parent child for communication and if you are closing proper descriptors in child & parents; they should work well. Its a pretty simple thing to code. However, this pipe method always results into half duplex communication channel.

Make sure to use two instances of pipes to make it a full duplex communication.

I guess, you don't require code examples (it's pretty simple one as I said) but should you really require, do let me know.

P.S. You really don't need any synchronization mechanism including semaphores. If child is not able to communicate, just look at your code and what descriptors you are reading/writing on.