Scroll to navigation

EXEC(3) Podręcznik programisty Linuksa EXEC(3)

NAZWA

execl, execlp, execle, execv, execvp, execvpe - uruchomienie pliku

SKŁADNIA

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


Wymagane ustawienia makr biblioteki glibc (patrz feature_test_macros(7)):

execvpe(): _GNU_SOURCE

OPIS

Rodzina funkcji exec() zastępuje w pamięci obraz bieżącego procesu obrazem nowego procesu. Funkcje opisane na tej stronie podręcznika są tylko nakładkami dla funkcji execve(2). (Dodatkowe informacje na temat nadpisywania bieżącego procesu można znaleźć na stronie podręcznika execve(2)).

Pierwszym argumentem tych funkcji jest ścieżka do pliku, który ma być uruchomiony.

The const char *arg and subsequent ellipses in the execl(), execlp(), and execle() functions can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. The first argument, by convention, should point to the filename associated with the file being executed. The list of arguments must be terminated by a null pointer, and, since these are variadic functions, this pointer must be cast (char *) NULL.

The execv(), execvp(), and execvpe() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers must be terminated by a null pointer.

Funkcje execle() i execvpe() pozwalają na podanie w parametrze envp środowiska wykonywanego procesu. Parametr envp jest tablicą wskaźników do zakończonych znakiem NUL łańcuchów znaków. Tablica ta musi być zakończona wskaźnikiem null. Pozostałe funkcje pobierają środowisko dla nowego procesu z zewnętrznej zmiennej environ procesu wywołującego te funkcje.

Special semantics for execlp() and execvp()

The execlp(), execvp(), and execvpe() functions duplicate the actions of the shell in searching for an executable file if the specified filename does not contain a slash (/) character. The file is sought in the colon-separated list of directory pathnames specified in the PATH environment variable. If this variable isn't defined, the path list defaults to a list that includes the directories returned by confstr(_CS_PATH) (which typically returns the value "/bin:/usr/bin") and possibly also the current working directory; see NOTES for further details.

Jeśli podana nazwa pliku zawiera znak ukośnika, to wartość zmiennej PATH jest ignorowana i wykonywany jest plik z podanej lokalizacji.

Dodatkowo pewne błędy są traktowane w specjalny sposób.

Jeśli dostęp do pliku został zabroniony (wywołanie execve(2) zakończyło się błędem EACCES), funkcje te będą przeszukiwać resztę ścieżki. Jeśli jednak nie odnajdą innego pliku, powrócą i ustawią wartość zmiennej errno na EACCES.

Jeśli nagłówek nie zostanie rozpoznany (wywołanie execve(2) zakończy się błędem ENOEXEC), funkcje te spróbują uruchomić powłokę (/bin/sh) ze ścieżką do pliku jako pierwszym argumentem. (Jeśli i ta próba się nie powiedzie, przeszukiwanie zostanie zakończone).

WARTOŚĆ ZWRACANA

Funkcje exec() powracają tylko wtedy, gdy wystąpi błąd. Zwracana jest wartość -1 i ustawiana jest zmienna errno, określająca rodzaj błędu.

BŁĘDY

Każda z tych funkcji może zakończyć się niepowodzeniem i ustawić jako wartość errno dowolny błąd określony dla execve(2).

WERSJE

Funkcja execvpe() pojawiła się po raz pierwszy w wersji 2.11 biblioteki glibc.

ATRYBUTY

Informacje o pojęciach używanych w tym rozdziale można znaleźć w podręczniku attributes(7).

Interfejs Atrybut Wartość
execl(), execle(), execv() Bezpieczeństwo wątkowe MT-Safe
execlp(), execvp(), execvpe() Bezpieczeństwo wątkowe MT-Safe env

ZGODNE Z

POSIX.1-2001, POSIX.1-2008.

execvpe() jest rozszerzeniem GNU.

UWAGI

The default search path (used when the environment does not contain the variable PATH) shows some variation across systems. It generally includes /bin and /usr/bin (in that order) and may also include the current working directory. On some other systems, the current working is included after /bin and /usr/bin, as an anti-Trojan-horse measure. The glibc implementation long followed the traditional default where the current working directory is included at the start of the search path. However, some code refactoring during the development of glibc 2.24 caused the current working directory to be dropped altogether from the default search path. This accidental behavior change is considered mildly beneficial, and won't be reverted.

Zachowanie execlp() oraz execvp() w przypadku wystąpienia błędów podczas uruchamiania pliku jest przyjęte jako tradycyjne, ale nie jest udokumentowane przez standard POSIX. BSD (a być może także inne systemy) po napotkaniu błędu ETXTBSY czeka przez chwilę i próbuje ponownie. Linux traktuje to jako błąd i powraca natychmiast.

Tradycyjnie funkcje execlp() oraz execvp() ignorowały wszystkie błędy oprócz podanych powyżej oraz ENOMEM i E2BIG, po których powracały. Obecnie powracają także wtedy, gdy wystąpi dowolny błąd inny od opisanych powyżej.

BŁĘDY

Before glibc 2.24, execl() and execle() employed realloc(3) internally and were consequently not async-signal-safe, in violation of the requirements of POSIX.1. This was fixed in glibc 2.24.

ZOBACZ TAKŻE

sh(1), execve(2), execveat(2), fork(2), ptrace(2), fexecve(3), system(3), environ(7)

O STRONIE

Angielska wersja tej strony pochodzi z wydania 4.16 projektu Linux man-pages. Opis projektu, informacje dotyczące zgłaszania błędów oraz najnowszą wersję oryginału można znaleźć pod adresem https://www.kernel.org/doc/man-pages/.

TŁUMACZENIE

Autorami polskiego tłumaczenia niniejszej strony podręcznika są: Adam Byrtek <alpha@irc.pl>, Andrzej Krzysztofowicz <ankry@green.mf.pg.gda.pl>, Robert Luberda <robert@debian.org> i Michał Kułach <michal.kulach@gmail.com>

Niniejsze tłumaczenie jest wolną dokumentacją. Bliższe informacje o warunkach licencji można uzyskać zapoznając się z GNU General Public License w wersji 3 lub nowszej. Nie przyjmuje się ŻADNEJ ODPOWIEDZIALNOŚCI.

Błędy w tłumaczeniu strony podręcznika prosimy zgłaszać na adres listy dyskusyjnej manpages-pl-list@lists.sourceforge.net.

15 września 2017 r. GNU