Difference between revisions of "Exec system call"
From Teknologisk videncenter
(Created page with "The '''exec()''' family executes a file as a new process. See fork system call for "cloning" a process. The =Simple use= The '''execlp()''' is one of the function call in...") |
m |
||
Line 3: | Line 3: | ||
The | The | ||
=Simple use= | =Simple use= | ||
− | The '''execlp()''' is one of the function call in the exec family. See manpage | + | The '''execlp()''' is one of the function call in the exec family. See manpage |
+ | |||
+ | '''execlp("ls", "ls", "-l", "/etc", NULL);''' arguments | ||
+ | #''ls'' - the executable file must be in $PATH | ||
+ | #''ls'' - argv[0] as seen from the executable file | ||
+ | #''-l'' - argv[1] as seen from the executable file | ||
+ | #''/etc'' - argv[2] as seen from the executable file | ||
+ | #''NULL'' argv[3] as seen from the executable file - end of argument list | ||
<source lang=c> | <source lang=c> | ||
#include <stdio.h> | #include <stdio.h> | ||
Line 9: | Line 16: | ||
int main() | int main() | ||
{ | { | ||
− | execlp("ls","ls","/etc", NULL); | + | execlp("ls", "ls", "-l", "/etc", NULL); |
return 1; | return 1; | ||
} | } |
Revision as of 08:49, 17 December 2022
The exec() family executes a file as a new process. See fork system call for "cloning" a process.
The
Simple use
The execlp() is one of the function call in the exec family. See manpage
execlp("ls", "ls", "-l", "/etc", NULL); arguments
- ls - the executable file must be in $PATH
- ls - argv[0] as seen from the executable file
- -l - argv[1] as seen from the executable file
- /etc - argv[2] as seen from the executable file
- NULL argv[3] as seen from the executable file - end of argument list
#include <stdio.h>
#include <unistd.h>
int main()
{
execlp("ls", "ls", "-l", "/etc", NULL);
return 1;
}