I have a little domain in C up to the pointers part (I'm a beginner), I have a college professor who passed a question about processes, I tried, but I do not know how to solve:
Question:
Knowing that the processes generated by the
fork( )
system call are encapsulated and protected, create a program in C using the call of systemfork ()
to generate a child, the parent being a counter of 0 the 10 assigned to a variable "A", and the child an adder of the variable "A" of the father plus "B = 10" of the child, and print the final sum of A + B through the child. Use the operating system API for the sharing of memory for the communication between these processes.
I tried to do in c ++ (I have more affinity), but did not rotate:
int main(){
pid_t filho;
int i,status;
pid_t pid;
filho=fork();
if(pid==0)
{
cout<<"Sou o processo filho"<<"\n";
for(i=0; i<10; i++){
int a=i;
cout<<i;
}
exit(0);
}
else
{
cout <<"Eu sou o pai , agora posso executar o meu código" << endl;
}
return 0;
}