一个C++多进程的例子

#include <iostream>
#include <unistd.h>

int main(int argc, char *argv[]) {
  pid_t pid = fork();
  if (pid > 0) {
    std::cout << "In parent process." << std::endl;
  }
  if (pid == 0) {
    std::cout << "In child process." << std::endl;
    execlp("echo", "", "Hello world!", NULL);
  }
}

  

posted @ 2024-02-26 16:16  南乡水  阅读(5)  评论(0编辑  收藏  举报