#include <sys/types.h>
#include <unistd.h>
#include <iostream>
using namespace std;
int main(void)
{
pid_t pid;
pid = fork();//建立新程序
if(pid == 0)//子程序
for(int i = 0;i < 50;i++)
cout << i << endl;
}
else if(pid > 0)
for(int i = 50;i < 100;i++)
cout << "*Father Process*" << endl;
else
cout << "ERRO" << endl;
exit(1);
exit(0);
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
using namespace std;
int main(void)
{
pid_t pid;
pid = fork();//建立新程序
if(pid == 0)//子程序
{
for(int i = 0;i < 50;i++)
cout << i << endl;
}
else if(pid > 0)
{
for(int i = 50;i < 100;i++)
cout << "*Father Process*" << endl;
}
else
{
cout << "ERRO" << endl;
exit(1);
}
exit(0);
}