1
0
UAHCode/CPE435/Lab2/lab2_ex1.cpp

24 lines
472 B
C++
Raw Permalink Normal View History

2022-08-28 21:12:16 +00:00
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;
}
}