-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec_param_test.cpp
More file actions
37 lines (30 loc) · 855 Bytes
/
exec_param_test.cpp
File metadata and controls
37 lines (30 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
extern int errno;
pid_t pid = fork();
if (pid < 0) {
printf("fork error!");
} else if (pid > 0) {
// parent
;
} else {
// child
// exec error: Bad address
// int ret = execl("/bin/ls", "ls", "-l", "../", "-tr");
// ok
// int ret = execl("/bin/ls", "ls", "-l", "../", 0);
// exec error: Bad address
// int ret = execl("/bin/ls", "ls", "-l", "../", 23);
// ls: cannot access -t ../: No such file or directory
int ret = execl("/bin/ls", "ls", "-l", " -t ../", (char*)0);
if (ret < 0) {
printf("exec error: %s\n", strerror(errno));
}
return 0;
}
return 0;
}