Estratto del documento

Exec Functions in Unix

Overview and Specifications

The exec functions replace the current process image with a new process image. The new image is constructed from a regular, executable file called the new process image file. There is no return from a successful exec because the calling process image is overlaid by the new process image.

Function Signatures

The following are the signatures for the exec functions:

  • #include <unistd.h>
  • extern char **environ;
  • int execl(const char *path, const char *arg0, ... /*, (char *)0 */);
  • int execv(const char *path, char *const argv[]);
  • int execle(const char *path, const char *arg0, ... /*, (char *)0, char *const envp[]*/);
  • int execve(const char *path, char *const argv[], char *const envp[]);
  • int execlp(const char *file, const char *arg0, ... /*, (char *)0 */);
  • int execvp(const char *file, char *const argv[]);

Main Function Entry

When a C-language program is executed as a result of this call, it is entered as a C-language function call as follows:

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

Here, argc is the argument count and argv is an array of character pointers to the arguments themselves. Additionally, the following variable is initialized:

extern char **environ;

It is a pointer to an array of character pointers to the environment strings. Both argv and environ arrays are terminated by a null pointer. The null pointer terminating the argv array is not counted in argc.

Multi-threaded Applications

Conforming multi-threaded applications will not use the environ variable to access or modify any environment variable while any other thread is concurrently modifying any environment variable. A call to any function dependent on any environment variable is considered a use of the environ variable to access that environment variable.

Arguments and Process Image

The arguments specified by a program with one of the exec functions are passed on to the new process image in the corresponding main() arguments. The argument path points to a pathname that identifies the new process image file. The argument file is used to construct a pathname that identifies the new process image file.

If the file argument contains a slash character, it is used as the pathname for this file. Otherwise, the path prefix is obtained by searching the directories passed as the environment variable. If this variable is not present, the results are implementation-dependent. execlp() and execvp() use the contents of that file as standard input to a command interpreter conforming to system(). In this case, the command interpreter becomes the new process image.

Argument Structure

The arguments represented by arg0, ... are pointers to null-terminated character strings. These strings constitute the argument list available to the new process image. The list is terminated by a null pointer. The argument arg0 should point to a filename associated with the process being started by one of the exec functions.

The argument argv is an array of character pointers to null-terminated strings, with the last member being a null pointer. These strings constitute the arguments passed to the new process image.

The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

Anteprima
Vedrai una selezione di 3 pagine su 6
Sistemi operativi - Syscall exec Pag. 1 Sistemi operativi - Syscall exec Pag. 2
Anteprima di 3 pagg. su 6.
Scarica il documento per vederlo tutto.
Sistemi operativi - Syscall exec Pag. 6
1 su 6
D/illustrazione/soddisfatti o rimborsati
Acquista con carta o PayPal
Scarica i documenti tutte le volte che vuoi
Dettagli
SSD
Scienze matematiche e informatiche INF/01 Informatica

I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher N. A. di informazioni apprese con la frequenza delle lezioni di Sistemi operativi e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Università degli studi di Napoli Federico II o del prof Cotroneo Domenico.
Appunti correlati Invia appunti e guadagna

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community