IPC between processes, pipes, etc


 
Thread Tools Search this Thread
Top Forums Programming IPC between processes, pipes, etc
# 1  
Old 05-27-2010
IPC between processes, pipes, etc

I need help with understanding this in C-programming style(the systemcalls only):
Three processes communicates via two pipes. (when the processes creates all stdin is the keyboard and all stdout is the screen)

This is how the communication goes:
Process 2 stdin (keyboard) and stdout goes via pipe2, this then becomes process 3:s stdin, and process 3:s stdout goes through pipe1, and then becomes Process 1:s stdin, Process 1:s stdout goes to the screen.

What is the system calls from each process(1, 2, 3)?
for example:
close(0);
dup(pipe2[0]);
etc,

(Donīt need to make a close where the need comes from the processes relationships)

Please help out! I just want the correct systemcalls, with the correct pipe and read or write end, so I get this finally :-)
# 2  
Old 05-27-2010
If you have to connect existing processes with pipes, you'll need to use named pipes, which can be created with the mkfifo() call and opened with the open() syscall, and duplicated over the required FD's with the dup2() syscall.

What's generally done so as to use anonymous pipes, is the parent process creates the necessary pipes with the pipe() syscall, does its own redirections with dup2(), forks, then the child does its own redirections. Any unnecessary duplicates of the pipe descriptors should be closed as soon as possible so your processes don't end up waiting on them.
# 3  
Old 05-27-2010
No that was not the answer i was looking for, I donīt think you understood my questions correct, I have example, and how the communication goes. But thank you anyway.
# 4  
Old 05-28-2010
You're missing my point. You can't connect processes that already exist with anonymous pipes. Therefore the instructions you want, connecting any 3 processes with pipes, simply don't exist.

All of the pipes must be created in the parent first. That way, when it creates children, they will share these pipes, allowing them(and of course the parent) to redirect their I/O through them how they please. To give more detailed instructions I'll need to know which of your processes created which others.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to properly connect these three processes using pipes?

I'm trying to properly connect three processes in order to allow inter-process communication between them. I have one process, scanner, which takes the parent's STDIN and then processes the words within the stream. If a word length is odd, it sends it to one process, if it is even, it sends it... (7 Replies)
Discussion started by: thomascirca
7 Replies

2. Programming

please help a problem in client-server ipc message 2 pipes communication simple example

I want to have a message send & receive through 2 half-duplex pipes Flow of data top half pipe stdin--->parent(client) fd1--->pipe1-->child(server) fd1 bottom half pipe child(server) fd2---->pipe2--->parent(client) fd2--->stdout I need to have boundary structed message... (1 Reply)
Discussion started by: ouou
1 Replies

3. Programming

Pipes connecting 3 processes in a "circle"

I am trying to get a better understanding of pipes and processes. I have code in which I link 3 processes A,B,C. I have A->B->C but how would I go about getting C->A? Here is my code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> main() { pid_t A, B, C; int fd; int fd2; ... (1 Reply)
Discussion started by: tfarmer4
1 Replies

4. UNIX for Dummies Questions & Answers

Mach IPC

hey everyone, I'm reading a tutorial on the Mach kernel principles, however, the port and port rights part are kind of confusing to me. I don't know if the book has typos or something but it seems a bit contradictory. It says that "ports, themselves, are not named. It is the port rights that are"... (10 Replies)
Discussion started by: neur0n
10 Replies

5. Programming

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... (5 Replies)
Discussion started by: pharaoh
5 Replies

6. Solaris

errors on Netra-440: "IPC Warning: ipc: tcp_protocol: bad magic number"

I was asked to look into a problem with a Sun Netra 440 in another department. On the server in question, the relevant 'uname -a' information is, "SunOS host1 5.9 Generic_118558-16 sun4u sparc SUNW,Netra-440". That information aside, while the other admin is logged into the ALOM, these errors are... (0 Replies)
Discussion started by: Borealis
0 Replies

7. Solaris

Identifying and grouping OS processes and APP processes

Hi Is there an easy way to identify and group currently running processes into OS processes and APP processes. Not all applications are installed as packages. Any free tools or scripts to do this? Many thanks. (2 Replies)
Discussion started by: wilsonee
2 Replies

8. UNIX for Advanced & Expert Users

Monitoring Processes - Killing hung processes

Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go? Thank you Richard (4 Replies)
Discussion started by: ukndoit
4 Replies

9. UNIX for Dummies Questions & Answers

Ipc

I have a parent that is passing data to child A and then child A has to process it and pass to child B. I am able to pass the data to child A but am not able to pass it to child B. Child B seems to only be receiving the last data instead of the whole data. I saw one example in a book but it uses... (1 Reply)
Discussion started by: scmay
1 Replies

10. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies
Login or Register to Ask a Question