Skip to main content

Posts

Showing posts with the label Network Programming

Difference between Pipe and Fifo

Pipe and Fifo both are IPC (Inter Process Communication) object.
Pipe (IPC Object)Pipe does not have any name unlike Fifo.Pipe is a structure of data which is contained into the memory. It is removed when existing process terminates.Basically, Pipe is used to communicate between 2 or more related processes.If Pipe is already in opened state, then it does not need to be opened.Pipe provides simplex data floweg: pipe(int fd[2]) Fifo (IPC Object)Fifo is also an IPC object, but it has its name.Unlike Pipe, it is a structure of file which is created in disc.It is also used for communication but only between unrelated processes.It should be opened every time when it needs to write and read.Fifo provides half duplex data flow.eg: mkfifo(const char * path_name, mode_t mode)

Inter Process Communication Objects - pipe()

In unix system, pipe is known as an inter process communication mechanism.A process can write data to pipe, and that data can be read by another process.In pipe IPC, the data is handled in fifo i.e first in first out order.Pipe does not have any name, it is only created for one use and both ends must be inherited from the single process which created the pipe.Since it is a IPC object, it is used to communicate between two process i.e parent and child.Pipe is created using pipe function (pipe()). Pipe also creates description pair which can be denoted as fd[0], fd[1]. Primarily fd[0] for reading and fd[1] for writing.As pipe sets up, the data can be passed using read and write functions.

Elementary System Calls - Wait() and Waitpid()

Wait function suspends the execution of the calling process until one of its children terminates.
Waitpid suspends execution of the calling process until a child specified by pid argument has changed state. Wait():Wait() continues to block the caller until a child process terminates.If there are more than one child running, wait() returns the first time one of the parent's offspring existsIt doesn't support job control.
Waitpid():It can be either blocking or non-blocking: if 0, blocking
if WNOHANG, non-blocking It is flexible
It waits for child process if pid is -1
It waits for child of greater process id if pid>0
It waits for any child whose process group ID equals that of the calling process if pid equals to 0.
It waits for any child whose process group ID equals that absolute value of pid. It supports job control.

exec() family calls - Network Programming

A child process (process created using fork()) can execute any other program using exec(). There are 6 exec() family calls in network programming.
The process is executed in memory by new program file from disk, and the process is replaced as well.

In here, the new program only executes; there is not being created new process. Therefore, no change occurs in process ID.

Six exec() family calls:

1) execl: 
execl is the first member of exec() family.It can take several arguments. It always takes full pathname as the first argument.It accepts a null pointer which marks the end of arguments in execl.

Lets see a simple example of execl. Lets suppose we have newscript.sh

#!/bin/ksh
echo "Hello Execl"
Now lets see a simple program which is written in C language to understand the actual use of execl.
void main()
{
      execl("/home/users/newscript.sh","newscript.sh",(char *)0);
      exit(0);
      getch();
}
2) execv: 
execl and execv works same, however, ther…

Elementary Operating System Call - Fork()

What is system call ? Karnel is the heart of Computer System. In computer system, a request has to be made by operating system to the Karnel in order to get the service, and it is only done in programmatic way, which is known as system call.

Program is a collection of instructions that is made to complete a particular task. And a process is a particular program which is currently in running status.

Thread includes in process i.e process has some properties of thread - a single sequence stream within process is called thread.


Fork() 

In UNIX system, we use Fork() to create duplicate of a process by creating address space for duplicate one.The process from which fork method is called, known as parent process. And child process is the new created process. Child and Parent, both processes return from the system call and execute the next instruction. Child process has all the features and ability of parent process i.e all memory segments of parent process are consumed by child process also.…