Donate SIGN UP

Can someone please explain to me these codes?

Avatar Image
iamalem | 18:29 Mon 29th Mar 2010 | Computers
2 Answers
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;
}
Gravatar

Answers

1 to 2 of 2rss feed

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.
All the cout lines are just sending characters to the output stream.

The main program displays that it has started etc., then spawns a copy of itself and displays a message if that is successful, and finally terminates that clone before terminating itself..
^^^ forget the terminating part of that answer, it's been years since I've written code.

1 to 2 of 2rss feed

Do you know the answer?

Can someone please explain to me these codes?

Answer Question >>

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.