-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMyexec(linux).txt
More file actions
34 lines (31 loc) · 831 Bytes
/
Myexec(linux).txt
File metadata and controls
34 lines (31 loc) · 831 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
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
pid_t id=fork();
if(id==0)
{//child
printf("i am child my id is: %d\n",getpid());
//int ret=execlp("ls","ls","-a","-l","-n",NULL);
char* argv[]={ "ls","-a","-l","-n",NULL};
int ret = execv("/bin/ls",argv);
// printf("i am child my id:%d\n",getpid());
if(ret==-1)
{
perror("execerror!\n");
exit(1);
}
exit(0);
}
else
{//father
pid_t ret=wait(NULL);
if(ret>0)
{
printf("child exit success! id:%d\n",ret);
printf("my child pid is:%d\n",id);
}
}
return 0;
}