0

With my lab work at uni I have to replace the pseudo code underlined with a method to solve the task involving to " call the loop method, passing in 2 to represent child", im really unsure on how to start this task.

if( childProcess >= 0 ) {
if( childProcess == 0 ) {
// this is the child process
printf("New process has id %d, parent id %d\n", getpid(), getppid() );
// call the loop method, passing in 2 to represent child
exit(0);
} else {
// this is the parent process
// call the loop method, passing in 1 to represent parent
}
} else printf("Error when trying to create a new process!\n");
return 0;
}
Cryces
  • 37
  • 1
  • please post a [mcve] so we can reproduce the problem and help you debug it. – user3629249 Nov 10 '19 at 22:12
  • for ease of readability and understanding: 1) separate code blocks; `for` `if` `else` `while` `do...while` `switch` `case` `default` via a single blank line. 2) please consistently indent the code. Indent after every opening brace '{'. unindent before every closing brace '}'. Suggest each indent level be 4 spaces. 3) please follow the axiom: *only one statement per line and (at most) one variable declaration per statement.* – user3629249 Nov 10 '19 at 22:15
  • regarding: `printf("Error when trying to create a new process!\n");` Error messages should be output to `stderr`, not `stdout` and when the error indication is from a C library function, should also output the text reason the system thinks the error occurred to `stderr`. The easy way to do this is via: `perror( "fork failed" );` Note: unrecoverable errors (normally) result in the program exiting ( with something like: `exit( EXIT_FAILURE );` rather than returning to the caller of the function. – user3629249 Nov 10 '19 at 22:22

0 Answers0