Crosswords12 mins ago
Can someone please explain to me these codes?
include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<iostream>
using std::cout;
using std::endl;
main()
{
int usaid;
int status;
cout<<endl<<endl;
cout<<'/a'<<"Process A has begun executing"<<endl;
cout<<"it's PID is "<<getpid()<<endl;
cout<<"Process A will wait for its children to exit"<<endl<<endl;
wait(&status);
sleep(10);
pid_t B=fork();
if(B==0)
{
cout<<'/a'<<"Process B has begun executing"<<endl;
cout<<"It's PID is "<<getpid()<<endl;
cout<<"it's PPID is "<<getppid()<<endl;
cout<<"Process B will now exit"<<endl<<endl;
exit(B);
}
exit(0);
return 0;
}
#include<unistd.h>
#include<sys/wait.h>
#include<iostream>
using std::cout;
using std::endl;
main()
{
int usaid;
int status;
cout<<endl<<endl;
cout<<'/a'<<"Process A has begun executing"<<endl;
cout<<"it's PID is "<<getpid()<<endl;
cout<<"Process A will wait for its children to exit"<<endl<<endl;
wait(&status);
sleep(10);
pid_t B=fork();
if(B==0)
{
cout<<'/a'<<"Process B has begun executing"<<endl;
cout<<"It's PID is "<<getpid()<<endl;
cout<<"it's PPID is "<<getppid()<<endl;
cout<<"Process B will now exit"<<endl<<endl;
exit(B);
}
exit(0);
return 0;
}
Answers
Best Answer
No best answer has yet been selected by iamalem. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.