EmbLogic's Blog

PIPES

Piping is a process where the output of one process is made the input of another.In numerous applications there is clearly a need for these processes to communicate with each exchanging data or control information.

Pipes can be used in threads and processes. A new process can be created using the system call fork(). It returns two differnt values to the child and parent. The value 0 is returned to the child (new) process and the PID (Process ID) of the child is returned to the parent process. This is used to distinguish between the two processes. In the program given below, the child process waits for the user input and once an input is entered, it writes into the pipe. And the parent process reads from the pipe.

the pipe() system call was called before the system call fork().the pipe has been set up, two (or more) cooperative processes will be created by a fork and data will be passed using read() and write(). Pipes opened with pipe() should be closed with close(int fd).

note:

1)pipe is always declared before fork.

2)switching is starts just after fork.for example

pid1=fork();
switch(pid1)
{
case 0:—.

case1:—.

}

3)if you are not using semaphore there will be some synchrosing error you can remove that using sleep and wait statements.

4)we can use sscanf()and sprintf() for converting string to variable and variable to string respectively.

5)In pipes ,by the use of command line argument(run time argument) for communication between server and client.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>