-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecve.c
More file actions
31 lines (30 loc) · 734 Bytes
/
execve.c
File metadata and controls
31 lines (30 loc) · 734 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
/*************************************************************************
> File Name: execve.c
> Author: jianghechao
> Mail: 591378033@qq.com
> Created Time: Sun 04 May 2014 12:03:29 PM CST
************************************************************************/
#include<stdio.h>
#include<sys/wait.h>
char *env_init[] = {"USER=unknown","PATH=/tmp",NULL};
int main()
{
pid_t pid;
if((pid=fork())<0)
perror("fork error");
else if(pid==0)
{
if(execle("/bin/ls","-l",(char *)0,env_init)<0)
perror("execle error");
}
if(waitpid(pid,NULL,0)<0)
perror("wait error");
if((pid=fork())<0)
perror("fork error");
else if(pid==0)
{
if(execlp("netstat","-a",(char *)0)<0)
perror("execlp error");
}
return 0;
}