来源:https://cplusplus.com/forum/general/85017/
#include<sys/types.h>
#include<iostream>
using namespace std;
int main()
{
int pid,ppid,cpid;
cout<<"Main Process with pid : "<<getpid();
cout<<"\nSplit starts : ";
pid=fork();
if(pid==0)
{
cout<<"\nChild Process with pid :"<<getpid();
}
else
{
cout<<"\nParent Process with pid :"<<getpid();
}
}