LAB-3      Process

 

1. Fork()

 

NAME

 

     fork - create a new process

 

SYNOPSIS

 

     #include <sys/types.h>

     #include <unistd.h>

 

     pid_t fork(void);

 

 

DESCRIPTION

 

     The fork() function creates a new process.   The new process (child process) is an exact copy of the calling process (parent process).

 

 

RETURN VALUES

 

     Upon successful completion, fork() return  0  to the  child  process  and  return the process ID of the child process to the  parent  process.   Otherwise,  (pid_t)-1 is returned to the parent process, no child process is created, and errno is set to indicate the error.

 

Example:


- fork.c

 

 

2. Execlp()

 

NAME

 

     execlp - execute a file

 

SYNOPSIS

 

     #include <unistd.h>

 

     int execlp (const char *file, const char *arg0, ...,  const char *argn, char * /*NULL*/);

 

DESCRIPTION

 

     Each of the functions in the exec family overlays a new process image on an old process.  The new process image is constructed from an ordinary, executable file.   This file is either an executable object file, or a file of data for an interpreter.  There can be no return from a successful call to one of these functions because the calling process image is overlaid by the new process image.  When a C program is executed, it is called as follows:

 

 int main (int argc, char *argv[], char *envp[]);

 

where argc is the argument count, argv is an array of character  pointers  to the arguments themselves, and envp is an  array of character pointers to the environment strings.   As indicated, argc is at least one, and the first member of the array points to a string containing the name of the file. The arguments arg0,..., argn point to null-terminated character strings.   These strings constitute the argument list available to the new process image.  Conventionally at least arg0 should be present.  It will become the name of the process.  The arg0 argument points to a string that is the same as path (or the last component of path).  The list of argument strings is terminated by a (char *)0 argument.

 

 

RETURN VALUES

 

     If a function in the exec family returns to the calling process, an  error  has  occurred;  the return value is -1 and errno is set to indicate the error.

 

Example:


- execlp.c

 

Hosted by www.Geocities.ws

1