01.03.2k10.txt

(1 KB) Pobierz
/*#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
	printf("Welcome to the QNX Momentics IDE\n");
	int pid1=0, pid2=0, status=0;
	printf("forkowanie...");
	fflush(stdout);
	if((pid1=fork())<0){
		printf("zonk");
	}
	else if(pid1==0){
		sleep(10);
		printf("potomny1\n");
	}
	else{
		//sleep(10);
		printf("rodzic %d\n", pid1);
		//waitpid(pid, &status,0);
		wait(&status);
		printf("koniec potomnego1 %d\n",status);
	}
	
	if((pid2=fork())<0){
		printf("zonk");
	}
	else if(pid2==0){
		sleep(5);
		printf("potomny2\n");
	}
	else{
		//sleep(10);
		printf("rodzic %d\n", pid2);
		//waitpid(pid, &status,0);
		wait(&status);
		printf("koniec potomnego2 %d\n",status);
	}
	
	return EXIT_SUCCESS;
}

//~jarocki/nps/nps.pdf
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
	int pid1 = 0;
	int pid2 = 0;
	int status1 = 0;
	int status2 = 0;
	printf("Welcome to the QNX Momentics IDE\n");
	printf("Forking!");
	fflush(stdout);
	if ((pid1 = fork()) < 0) {
		printf("Fork failed!\n");
	}
	if(pid1 == 0) {
		sleep(5);
		printf("In child 1!\n");
	} else {
		if ((pid2 = fork()) < 0) {
			printf("Fork failed!\n");
		}
		if (pid2 == 0) {
			sleep(5);
			printf("In child 2!\n");			
		} else {
		//sleep(10);
		waitpid(pid1, &status1, 0);
		waitpid(pid2, &status2, 0);
//			wait(&status1);
			printf("Child 1 exited with status %d\n", status1);
			printf("Child 2 exited with status %d\n", status2);
			printf("In parent\n");
		}
	}
	return EXIT_SUCCESS;
}

Zgłoś jeśli naruszono regulamin