Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ex1/ex1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@

int main(void)
{
// Your code here
int x = 100;

printf("pre-fork: parent pid %d, x = %d \n", (int)getpid(), x);

int rc = fork();

if (rc < 0)
{
fprintf(stderr, "fork failed\n");
exit(1);
}
else if (rc == 0)
{
printf("post-fork: child pid %d, x = %d \n", (int)getpid(), x);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like how you structured this. It's very detailed.

}
else
{
printf("post-fork: parent pid %d of child %d, x = %d\n", (int)getpid(), rc, x);
}

return 0;
}