linux多进程代码

 

#include <iostream>
#include<unistd.h>
#include<sys/types.h>
using namespace std;
int main()
{
 int i;
 if (fork() == 0)
 {
  /* 子进程程序 */
  for (i = 1; i < 1000; i++)
   cout<<"子进程"<<i<<endl;
 }

 else
 {
  /* 父进程程序*/
  for (i = 1; i < 1000; i++)
   cout<<"父进程"<<i<<endl;
 }
 getchar();
 return 0;
}

 

 

posted @ 2012-03-15 16:04  byfei  阅读(114)  评论(0编辑  收藏  举报