İşletim Sistemleri (Bahar-2016) Hafta-4

#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>

using namespace std;

int main()
{
	pid_t pid;
	
	cout<<"Proc id:"<<getpid()<<endl;
	
	pid=fork();
	
	if(pid==0) // cocuk	
	{
		cout<<"BEN COCUK, PROC ID:"<<getpid()<<endl;
		cout<<"COCUK: BEN UYUDUM"<<endl;
		sleep(20);
		cout<<"COCUK: BEN UYANDIM"<<endl;
		cout<<"COCUK: BEN SONLANDIM"<<endl;
	}
	else{
	
		if(pid>-1)
			cout<<"COCUK PID:"<<pid<<endl;
		else
			cout<<"COCUK OLUSMADI"<<endl;	 
		cout<<"ANNE PID:"<<getpid()<<endl;
		
		waitpid(pid,0,0);
		cout<<"ANNE: BEN SONLANDIM"<<endl;
	}

	return 0;
}

 

Share