3 ms·
It replaces the executable in the current process with a different executable. It's kind of like spawning a new process with an executable, except it's the same
by kccqzy 6y ago
It replaces the executable in the current process with a different executable. It's kind of like spawning a new process with an executable, except it's the same PID, and file descriptors without CLOEXEC remain open in their original state.
- uryga 6y agowould `become` be a good alternate name for it?
- yjftsjthsd-h 6y agoThat's loosely correct.
- asdff 6y agowhats a simple example of using this?
- gorgoiler 6y agoIt’s how all new processes in Unix are created. There is no “spawn new process running this code” operation. Instead: (1) you duplicate yourself with fork() (2) the parent process continues about its business (3) the created process calls execve() to become something else This is the mechanism by which all new processes are created, from init (process 1) to anything you run from your shell. Real life examples here, in this example of a Unix shell: https://github.com/mirror/busybox/blob/master/shell/ash.c https://github.com/mirror/busybox/blob/master/shell/ash.c
- Icathian 6y agoBash is probably the best example of this style of working. You have a shell process that forks and spawns child processes from itself that are turned into whatever program you've called from your terminal.
- zwetan 6y agosee here: https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/e... plenty of basic examples with execv, execve, execvp, etc. if the execv() call succeed then it completely replaces the program running in the process that calls it you can do plenty of tricks with that ;)