[man] execve

숭글·2022년 11월 7일
0

execve

#include <unistd.h>

int execve(const char *pathname, char *const argv[], char *const envp[]);

executes the program referred to by pathname.

This causes the program that is currently being run by the calling process to be replaced with a new program, with newly initialized stack, heap, and (initialized and uninitialized) data segments.

parameters

  • pathname must be
    • a binary executable
    • script (starting with a line of the form👇)
    #!interpreter [optional-arg]
  • argv
    : an array of pointers to strings passed to the new program as its command-line arguments.
    • argv[0] should contain the filename associated with the file being executed.
    • array must be terminated by a NULL pointer.
  • envp
    : an array of pointers to strings, conventionally of the form key=value, which are passed as the environment of the new program.
    • array must be terminated by a NULL pointer.

return value

: execve() does not return on success.
the text, initialized data, uninitialized data (bss), and stack of the calling process are overwritten according to the contents of the newly loaded program.

Effect on process attributes

All process attributes are preserved during an execve(), except the following:

  • The dispositions of any signals that are being caught are reset to the default (signal(7)).

  • Any alternate signal stack is not preserved (sigaltstack(2)).

Memory mappings are not preserved (mmap(2)).

📝 note

  • the use of a third argument to the main function is not specified in POSIX.1; according to POSIX.1, the environment should be accessed via the external variable environ(7).

  • All threads other than the calling thread are destroyed during an execve(). Mutexes, condition variables, and other pthreads objects are not preserved.

  • Any outstanding asynchronous I/O operations are canceled (aio_read(3), aio_write(3)).

  • By default, file descriptors remain open across an execve(). File descriptors that are marked close-on-exec are closed.


📖 execve

profile
Hi!😁 I'm Soongle. Welcome to my Velog!!!

0개의 댓글