I'm writing a program that contains two processes. One process gets two numbers from input, and add them together. The second process shows the added result.
The problem is it can't get number from input.
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int a,b,c=1;
bool res = false;
void Add(){
if(res==true){
c=a+b;
cout<<"Process 1 was done !\n";
cout<<c<<endl;}
}
void Print(){
if(c!=1){
cout<<c<<endl;
cout<<"Process 2 was done !\n";}
}
int main(){
cout<<"Enter a,b :\n";
cin>>a>>b;
res= true;
pid_t pid;
pid = fork();
if(pid==0)
Print();
else
Add();
return 0;}
Running on Ubuntu.