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, there is a minor difference between them and i.e arguments for the script in the array can be passed in execv, but execl passes them individually.

3) execlp: 

execl and execv are same but in execlp we only pass the name of script unlike execl on which full path is passed.

4) execvp:

exev and excvp are same but excvp takes the full path of script and only replaces the individual arguments given in the execlp. 

5) execle

Unlike other methods, it takes extra environmental argument variable. 

6) execve:

It works same as execle does, however unlike the execle, it takes arguments for the script in an array.


Synopsis of different exec() family calls:

int execl(const char *pathname, const char *argument(),......., const char *argmentName, (char *)0);
int execle(const char *pathname, const char *argument(),......., const char *argmentName, (char *)0, char * const envp[]);
int execlp(const char *filename, const char *argument(),......., const char *argmentName, (char *)0);
int execv(const char *pathname, char * const argumentValue[]);
int execve(const char *pathname, char * const argumentValue[], char * const envp[]);
int execvp(const char *filename, char *argumentValue[]);


Post a Comment

0 Comments