Skip to content
Open
Changes from 2 commits
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
19 changes: 18 additions & 1 deletion ex1/ex1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@

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

printf("Parent PID: %d, x = %d \n", (int)getpid(), x);

int rc = fork();

if (rc == 0)
{
printf("Fork successful. We are the child process.\n Child PID: %d, Parent PID: %d", getpid(), getppid());
}
else if (rc > 0)
{
printf("We are the parent process.\n Parent PID: %d of Child PID: %d", getpid(), rc, x);
}
else
{
printf(stderr, "Fork failed");
}

return 0;
}