#include <stdlib.h> int system (const char *string);
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("Running ps with system\n");
//ps进程结束后才返回,才能继续执行下面的代码
system("ps au");// 1
printf("ps Done\n");
exit(0);
}
#include <unistd.h> char **environ; int execl (const char *path, const char *arg0, ..., (char*)0); int execlp(const char *file, const char *arg0, ..., (char*)0); int execle(const char *path, const char *arg0, ..., (char*)0, char *const envp[]); int execv (const char *path, char *const argv[]); int execvp(cosnt char *file, char *const argv[]); int execve(const char *path, char *const argv[], char *const envp[]);
char *const ps_envp[] = {"PATH=/bin:usr/bin", "TERM=console", 0};
char *const ps_argv[] = {"ps", "au", 0};
execl("/bin/ps", "ps", "au", 0);
execlp("ps", "ps", "au", 0);
execle("/bin/ps", "ps", "au", 0, ps_envp);
execv("/bin/ps", ps_argv);
execvp("ps", ps_argv);
execve("/bin/ps", ps_argv, ps_envp);
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Running ps with execlp\n");
execlp("ps", "ps", "au", (char*)0);
printf("ps Done");
exit(0);
}
#include <sys/type.h> #include <unistd.h> pid_t fork();
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
pid_t pid = fork();
switch(pid)
{
case -1:
perror("fork failed");
exit(1);
break;
case 0:
//这是在子进程中,调用execlp切换为ps进程
printf("\n");
execlp("ps", "ps", "au", 0);
break;
default:
//这是在父进程中,输出相关提示信息
printf("Parent, ps Done\n");
break;
}
exit(0);
}
#include <sys/types.h> #include <sys/wait.h> pid_t wait(int *stat_loc); pid_t waitpid(pid_t pid, int *stat_loc, int options);
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
pid_t pid = fork();
int stat = 0;
switch(pid)
{
case -1:
perror("fork failed");
exit(1);
break;
case 0:
//这是在子进程中,调用execlp切换为ps进程
printf("\n");
execlp("ps", "ps", "au", 0);
break;
default:
//这是在父进程中,等待子进程结束并输出相关提示信息
pid = wait(&stat);
printf("Child has finished: PID = %d\n", pid);
//检查子进程的退出状态
if(WIFEXITED(stat))
printf("Child exited with code %d\n", WEXITSTATUS(stat));
else
printf("Child terminated abnormally\n");
printf("Parent, ps Done\n");
break;
}
exit(0);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有