Example #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;
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}