You are on page 1of 5

17BCE0511 Harsh Agarwal

OPERATING SYSTEM (CSE 2005)


ASSIGNMENT 1

NAME – Harsh Agarwal

Reg no – 17BCE0511

Question – In a fork system call, which order does the processor execute using pid –

1. First parent then child


2. First child then parent
3. Both simultaniously

Answer –
17BCE0511 Harsh Agarwal

In the above code we are using a int variable x to store the return value of fork() system call. The
return valuse of a fork system call for a child process is always 0. Hence, when we print the value of
x, for child process it is 0.

Therefore the child process is executed first and then the parent process is executed.
17BCE0511 Harsh Agarwal

In the second output, 3 child processes were run first and then all the parent processes. The rest 2
child processes in the last.
17BCE0511 Harsh Agarwal

In the third one, now there is a mix match of the parent and child processes, the ) after the print
statement is run tells that it is a child process.
17BCE0511 Harsh Agarwal

In the fourth one the child processes are executed first and then the parent process.

You might also like