24 lines
472 B
C++
24 lines
472 B
C++
|
using namespace std;
|
||
|
#include <iostream>
|
||
|
#include <stdlib.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/wait.h>
|
||
|
|
||
|
int main(int argc, char * argv[])
|
||
|
{
|
||
|
int val = 0;
|
||
|
int pid;
|
||
|
pid = fork();
|
||
|
if (pid == 0 ) /* we are the child */
|
||
|
{
|
||
|
val=+2;
|
||
|
cout << "Id: " << getpid() << "\tVal: " << val << endl;
|
||
|
}
|
||
|
else //(getpid > 0) // we are the parent
|
||
|
{
|
||
|
val=+5;
|
||
|
cout << "Id: " << getpid() << "\tVal: " << val << endl;
|
||
|
}
|
||
|
}
|