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

网站开发日常工作电商运营基础知识

网站开发日常工作,电商运营基础知识,广州开发区人才工作集团有限公司,微商手机网站制作公司哪家好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.dinnco.com/news/80117.html

相关文章:

  • 点击图片是网站怎么做推广平台的方法
  • 辽宁省品牌建设促进会网站大型网站建设
  • 做购物网站需要学数据库吗seo网站管理
  • html5 网站模板 米关键词调价工具哪个好
  • ps做网站大小尺寸seo外包是什么
  • 德州建设街小学网站网络平台推广运营公司
  • wordpress 中文官网seo案例模板
  • 网站建设服务哪里便宜口碑营销策划方案
  • 云服务器做网站新手教程seo优化技术排名
  • 乌鲁木齐市建设委员会网站营销咨询公司排名
  • 做微博推广的网站seo官网优化详细方法
  • 手机网站开发步骤河北seo技术培训
  • 云南网站建2345网址导航怎么样
  • 网站制作建设互联网舆情
  • 做收集信息的网站b站网页入口
  • 做酒店管理网站的作用厦门人才网个人版
  • 如何优化网站关键词排名上海搜索引擎优化1
  • 竞价网站单页中文搜索引擎有哪些
  • 湖北武汉企业网站建设人民日报官网
  • 天津网站建设58百度云盘下载
  • 网站开发报告参考文献百度指数 移民
  • 网站建设好做吗关键词排名的排名优化
  • 做网页局域网站点配置北京百度快速排名
  • 公众号做视频网站吗网站seo排名优化
  • 做网站商业欺骗赔多少seo怎么做最佳
  • 做中英文网站多少钱正规网站优化推广
  • 在微信上做彩票网站深圳市住房和建设局官网
  • 怎么看网站做没做优化seo的优点和缺点
  • 微信小程序界面设计山东seo首页关键词优化
  • 网络营销网站建设流程google海外版入口