封装 fork wait execvp, 编写函数 process_create
2018-03-25 09:51
232 查看
利用回调函数封装fork wait execvp 等函数, 编写一个progress_create函数
#include<stdio.h> #include<stdlib.h> #include<unistd.h> int process_create(int(*func)(), const char *file, char *argv[]) { int ret = 0; pid_t pid = fork(); if(pid == 0) { //子进程 ret = func(file, argv); if(ret == -1) { printf("调用execvp失败\n"); perror("func"); _exit(-1); } } else { int st; pid_t ret = wait(&st); if(ret == -1) { perror("wait"); exit(-1); } } return 0; } int main() { 997d char *argv1[] = {"ls"}; char *argv2[] = {"ls", "-al", "/etc/passwd", 0}; process_create(execvp, *argv1, argv2); return 0; }
相关文章推荐
- 模拟shell ( 进程函数:fork(),execvp(),wait() )
- 进程监视函数PsSetCreateProcessNotifyRoutine
- wait/waitpid函数与僵尸进程、fork 2 times
- [linux c] fork 等函数编写执行命令实验
- 淘宝服务市场 上架封装类 (仅提供思路, 类内调用的函数还需要您自己编写)
- vc中调用其他应用程序的方法(函数) winexec,shellexecute ,createprocess .
- linux系统编程之进程(四):wait/waitpid函数与僵尸进程、fork 2 times
- 赞!VC++编程创建远程线程式调用CALL_VirtualAllocEx_WriteProcessMemory_CreateRemoteThread_WaitForSingleObject
- wait函数在fork创建子进程后的使用
- HYDU_create_process (./utils/launch/launch.c:69): execvp error on file Demo_00.exe (No such file or
- 创建新进程,就三个函数CreateProcessAsUser CreateProcessWithLogonW CreateProcessWithTokenW(附网友的流程)
- 多进程函数系列fork(), wait(), exec()系列,system(), posix_spawn()实例详解
- HYDU_create_process (./utils/launch/launch.c:75): execvp error on file *
- 实现函数 process_create
- python的os模块fork、wait、system、exec、popen、exit函数讲解
- 无法解析的外部符号 _DetourCreateProcessWithDllW@48,该符号在函数 _WinMain@16 中被引用
- fork函数和wait/waitpid函数
- Linux下进程管理(函数fork,wait,exec的用法)
- wait && child process && fork
- 基于fork(),execvp()和wait()实现类linux下的bash——mybash