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

江宁网站建设价格资讯网站源码

江宁网站建设价格,资讯网站源码,广告传媒公司简介ppt,可以进行网站外链建设的有Linux进程编程(PS: exec族函数、system、popen函数)_linux popen函数会新建进程吗-CSDN博客 execvp函数详解_如何在C / C 中使用execvp()函数-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.h>int 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.h>int 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 2>&1",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  2>&1 ";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  2>&1 ";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.yayakq.cn/news/665159/

相关文章:

  • 深圳专业做网站排名多少钱哪里可以大量找到广告主
  • excel做网站数据库徐州建设工程招标信息网官网
  • 中天建设集团山西分公司网站河北搜索引擎推广价格
  • 营销型网站建设是什么意思东莞推广
  • wordpress网站被拒登天津建设网站首页
  • 怎么建网站教程视频软装设计师证
  • 旅行网站系统企业网站广告图片轮播代码
  • 网站轮播图怎么保存网站做百度口碑
  • 兰州建设一个网站多少钱怎么生成二维码
  • 网站设计工作流程徐州建站费用
  • 最好的模板网站网站设计建设专业服务
  • 在郑州网站推广注册网站借钱平台犯不犯法
  • 网站排名优化wordpress j建站
  • 动态asp.net网站开发苏州网站建设网站制作的公司
  • php网站开发程序编译软件泰安最好的房产中介
  • 网站开发过时了包装设计模板
  • 网站建设费用报价单wordpress search
  • 建设网站开通网线多少钱微信网页版登录手机版
  • 网上书店网站建设毕业设计范文中国移动积分商城官网
  • php带数据库的网站wordpress移动端音频播放
  • 重庆网站建设网络推广购物网站排行
  • 产品列表型网站模板做母婴用品的网站有哪些
  • 使页面具有动态效果的网站建设技术是新网站要多久收录
  • 坊网站建设在百度上做公司做网站
  • 零度业务网站怎样建立网站免费的
  • 网站建设的可行性分析顺电网上商城
  • 酒店预定类网站建设阳信做网站
  • 四川城乡建设部网站首页什么管理系统好做
  • 德州聊城网站建设建设发展集团有限公司
  • 网站备案系统源码电子商城网站开发支持手机端