Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c fork wait for child

int main(){
    pid_t pid = fork();
    if (pid == 0) {
        printf("HC: hello from child
");
        exit(17);
    } else {
        int child_status;
        printf("HP: hello from parent
");
        waitpid(pid, &child_status, 0); // Waits for child to end
        printf("CT: child result %d
", WEXITSTATUS(child_status));
    }
    printf("Bye
");
    return 0;
}
Source by my.eng.utah.edu #
 
PREVIOUS NEXT
Tagged: #fork #wait #child
ADD COMMENT
Topic
Name
2+7 =