功 能: 装入并运行其它程序的函数
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL)
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
char *envp[])
int execlp(char *pathname, char *arg0, arg1, .., NULL)
int execple(char *pathname, char *arg0, arg1, ..., NULL,
char *envp[])
int execv(char *pathname, char *argv[])
int execve(char *pathname, char *argv[], char *envp[])
int execvp(char *pathname, char *argv[])
int execvpe(char *pathname, char *argv[], char *envp[])
程序例: /* execv example */
#include <process.h>
#include <stdio.h>
#include <errno.h>void main(int argc, char *argv[])
{
int i printf("Command line arguments:\n")
for (i=0i<argci++)
printf("[%2d] : %s\n", i, argv[i]) printf("About to exec child with arg1 arg2 ...\n")
execv("CHILD.EXE", argv) perror("exec error") exit(1)
}
多看书,多Google,百度,
例:
#include<stdio.h>
intsushu(intx)
{inti
for(i=2i<xi++)
if(x%i==0)break
if(i==x)return1
elsereturn0
}
main()
{inti,n=0
for(i=2i<=1000i++)
if(sushu(i)==1)n++:
printf("n=%d",n)
}
扩展资料
使用vfork()新建子进程,然后调用exec函数族
#include<unistd.h>
main()
{
char*argv[]={“ls”,”-al”,”/etc/passwd”,(char*)}
if(vfork()==0)
{
execv(“/bin/ls”,argv)
}else{
printf(“Thisistheparentprocess\n”)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)