当前位置: 首页 > news >正文

北京经济技术开发区建设局网站温州网站制作策划

北京经济技术开发区建设局网站,温州网站制作策划,深圳专业商城网站制作公司,汇通网做期货的网站做期货的网站Linux进程编程(PS: exec族函数、system、popen函数)_linux popen函数会新建进程吗-CSDN博客 execvp函数详解_如何在C / C 中使用execvp#xff08;#xff09;函数-CSDN博客 C语言的多进程fork()、函数exec*()、system()与popen()函数_c语言 多进程-CSDN博客 Linux---fork…Linux进程编程(PS: exec族函数、system、popen函数)_linux popen函数会新建进程吗-CSDN博客 execvp函数详解_如何在C / C 中使用execvp函数-CSDN博客 C语言的多进程fork()、函数exec*()、system()与popen()函数_c语言 多进程-CSDN博客 Linux---fork函数和exec函数_fork exec-CSDN博客 #include unistd.hint main() {pid_t childPid fork(); //创建子进程if (childPid -1) {perror(fork);return 1;} else if (childPid 0) {// 子进程的代码char* args[] {/bin/sh, -c, logcat | grep, NULL};int result execvp(args[0], args);if (result -1) {perror(execvp);exit(EXIT_FAILURE);}} else {// 父进程的代码waitpid(childPid, NULL, 0); //等待子进程结束}return 0; } #include iostream #include stdio.h #include unistd.h // for getpid() function #include sys/wait.h #include string.h #include chrono #include thread #include unistd.h#include sys/types.h #include sys/stat.h #include fcntl.hint main() {char *p (char*)malloc(5000);strcpy(p, ifsddsffdsdsdfsfdssdffds);pid_t pid fork(); // 创建子进程if (pid 0) {int status;// wait(status); // 等待子进程结束std::this_thread::sleep_for(std::chrono::milliseconds(3000));// std::string cmd_str kill -9 std::to_string(pid);//pkill -TERM -P 27888std::string cmd_str pkill -TERM -P std::to_string(pid);auto ret system(cmd_str.c_str());std::cout Child process ID is: pid std::endl;} else if (pid 0) {char *a (char*)malloc(100);// std::this_thread::sleep_for(std::chrono::milliseconds(3000));#if 1std::string cmd_log /home/zeekr/code/test/test;// 关闭标准输入、输出和错误流close(STDIN_FILENO);close(STDOUT_FILENO);close(STDERR_FILENO);// 打开要写入的文件int fd open(output.txt, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);// 设置新的标准输出为指定文件dup2(fd, STDOUT_FILENO);// 执行需要重定向的命令// execlp(/bin/ls, ls, -la, NULL);// execlp(cmd_log.c_str(), test, 3, NULL);// execl(cmd_log.c_str(),test, 3, a.txt 21,NULL);char* args[] {/bin/sh, -c, logcat | grep xxx, NULL};int result execvp(args[0], args);if (result -1) {perror(execvp);exit(EXIT_FAILURE);}// execl(/bin/ls, ls, -l, NULL);perror(Child failed to exec ls);//execl后面的代码都不会执行了printf(chlid end\n);exit(0);//让子进程到这里就结束#elif 0std::string cmd_log top a.txt 21 ;auto status system(cmd_log.c_str());printf(system: %d\n, status);std::this_thread::sleep_for(std::chrono::milliseconds(30000));printf(exit(EXIT_SUCCESS);\n);exit(EXIT_SUCCESS);#elif 0std::string cmd_log top a.txt 21 ;FILE* pipe popen(cmd_log.c_str(), r); // 这里以ls命令为例也可以根据需求修改成其他命令或脚本if (pipe nullptr) {std::cout Failed to create child process. std::endl;return -1;}// 子进程部分char buffer[256];while (!feof(pipe)) {fgets(buffer, sizeof(buffer), pipe);printf(result: %s\n, buffer);}pclose(pipe); // 关闭管道printf(pclose(pipe); : %s\n, buffer);exit(EXIT_SUCCESS); #endif} else {std::cerr Fork failed! std::endl;return -1;}return 0; }
http://www.tj-hxxt.cn/news/140820.html

相关文章:

  • 营销型网站建设明细软件开发报价明细
  • 成都私人网站制作公司西安网站建设 招聘
  • 广西柳州网站制作公司h5个网站的区别
  • 彩票网站开发软件中国建设银行巴黎分行网站
  • wap网站开发语言临沂网站建设铭镇
  • 厦门大型企业网站开发公司品牌seo如何优化
  • 简易php企业网站源码国际贸易
  • 南宁建站模板展示萧山工程建设有限公司网站
  • 图片网站怎么做优化高仿卡西欧手表网站
  • 制作地图的网站提供设计的网站
  • 做移动端网站软件开发wordpress 分页不出来
  • 如何做网站热力图广州h5网站开发
  • 网站与网页的关系网站安全建设总结报告
  • 手机网站使用微信支付企业网站怎样做
  • 怎么样通过做网站赚钱吗产品推广的句子
  • 济南行知网站建设创意专业网站建设
  • 智慧团建网站登录密码是啥汕头微信推广平台
  • 网站需要兼容哪些浏览器网站建设原因
  • 阳江营销网站开发游戏攻略网站开发
  • wordpress采集站源码承德房地产网站建设
  • 惠州住房和城乡建设厅网站wordpress code 样式
  • 互联网创业项目整合网站wordpress 获取副标题
  • 怎么把网站生成二维码世界500强
  • 怎么知道网站的空间是谁做的浙江省建设局教育网站
  • 学会建设网站必要性163免费邮箱入口
  • 旅游网站效果图网站网页栅格化
  • 搜索企业信息的网站如何做同城信息网站
  • 锚文本外链网站在线制作电子公章免费公章在线生成
  • 南昌网站设计案例现在能不能去北京
  • 二级网站建设 管理思路wordpress邀请码计数