Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
        pid_t pid;
	int status;
	struct tree_node *root;

        if (argc != 2) {
                fprintf(stderr, "Usage: %s <input_tree_file>\n\n", argv[0]);
                exit(1);
        }

        root = get_tree_from_file(argv[1]);
        print_tree(root);

	pid=fork();
	if(pid<0){
		perror("main: fork");
		exit(1);
	}
	else if(pid==0){
		fork_procs(root);
		exit(1);
	}
		
	wait_for_ready_children(1);
	show_pstree(pid);
	kill(pid,SIGCONT);
        pid=wait(&status);
	explain_wait_status(pid,status);

	return 0;
}
Ejemplo n.º 2
0
//--ENTRY POINT--
int main (int argc, char **argv) {
	if (argc!=2) {		//Argument validation.
		fprintf(stderr, "Invalid argument number. Terminating...\n");
		exit(EXIT_FAILURE);
	}
	mainrt=getpid();
	 node_type *root=get_tree_from_file(argv[1]);	//Read tree: we suppose non-empty return tree.
	 pid_t _fork;
	 int k[2];
	if (pipe(k)) {				//Pipe error.
		pipe_error(mainrt);
		exit(EXIT_FAILURE);
	}
	if ((_fork=fork())==-1) {	//Fork error.
		fprintf(stderr, "Fork error at main. ERRNO: (%d).\n", errno);
		exit(EXIT_FAILURE);
	} else if (_fork==0) {		//Child:
		ccret(close(k[0]));
		fork_proc(root, k[1]);
	} else {					//Main:
		ccret(close(k[1]));
		int rwn=0, rwrv=0, result;
		while (rwn<sizeof(int)) {		//Read result.
			if ((rwrv=read(k[0], &result+rwn, sizeof(int)-rwn))==-1) {
				read_err(getpid());
				exit(EXIT_FAILURE);
			}
			rwn+=rwrv;
		}
		ccret(close(k[0]));
		printf("RESULT: %d\n", result);	//Print result.
	}	
	return 0;
}
Ejemplo n.º 3
0
//--ENTRY POINT--
int main (int argc, char *argv[]) {
	if (argc!=2) {
		fprintf(stderr, "Invalild number of arguments.\n");
		return 1;
	}
	 node_type *root;
	root=get_tree_from_file(argv[1]);
	 pid_t FIRST;
	 int status;
	FIRST=fork();
	if (FIRST<0) {
		fork_err(getpid());
		exit(EXIT_FAILURE);
	}
	if (FIRST==0) {		//Process Tree R00T:
		create_ptree(root, 0);
		exit(EXIT_SUCCESS);
	} else {			//MAIN:
		wait_for_ready_children(1);
		//All children are in slumber!
		show_pstree(FIRST);
		kill(FIRST, SIGCONT);
		if ((wait(&status))==-1) {
			sign_err(FIRST, "main");
			exit(EXIT_FAILURE);
		} else {
			explain_wait_status(FIRST, status);
		}
	}
	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	pid_t pid;
	int status;
	struct tree_node *root;
	if (argc != 2) {
                fprintf(stderr, "Usage: %s <input_tree_file>\n\n", argv[0]);
                exit(1);
        }
	root = get_tree_from_file(argv[1]);	/*get tree (tree_node)*/
	pid = make_proc_tree(root);	/*returns pid of root (the first call of the function)*/
	sleep(SLEEP_TREE_SEC); 	/*sleep until all procedures of tree created*/
        show_pstree(pid);	/* Print the process tree root at pid */
        pid = wait(&status);	/* Wait for the root of the process tree to terminate */
        explain_wait_status(pid, status);
	return 0;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	pid_t pid;
	int status;
	struct tree_node *root;

	if (argc < 2){
		fprintf(stderr, "Usage: %s <tree_file>\n", argv[0]);
		exit(1);
	}

	/* Read tree into memory */
	root = get_tree_from_file(argv[1]);

	/* Fork root of process tree */
	pid = fork();
	if (pid < 0) {
		perror("main: fork");
		exit(1);
	}
	if (pid == 0) {
		/* Child */
		fork_procs(root);
		exit(1);
	}

	/*
	 * Father
	 */
	/* for ask2-signals */
	wait_for_ready_children(1);

	/* Print the process tree root at pid */
	show_pstree(pid);

	/* for ask2-signals */
	kill(pid, SIGCONT);

	/* Wait for the root of the process tree to terminate */
	pid = wait(&status);
	explain_wait_status(pid, status);

	return 0;
}