## System-Calls

 Question 1

The following C program is executed on a Unix/Linux system:

```            #include <unistd.h>
int main ()
{
int i ;
for (i=0; i<10; i++)
if (i%2 == 0) fork ( ) ;
return 0 ;
}
```

The total number of child processes created is _____.

 A 26 B 33 C 31 D 28
Operating-Systems       System-Calls       GATE 2019       Video-Explanation
Question 1 Explanation:
Fork( ) statement is executed when 'i' is even. Thus the above code is equivalent to
#include
int main( )
{
int i;
fork( );
fork( );
fork( );
fork( );
fork( );
}
n - fork statements will have 2n-1 child.
Hence, n = 5 ⇒ We have 31 child processes.
 Question 2

A process executes the code

```fork();
fork();
fork();```

The total number of child processes created is

 A 3 B 4 C 7 D 8
Operating-Systems       System-Calls       GATE 2012
Question 2 Explanation:
The no. of child process created = 2n - 1 = 23 - 1 = 7 (where n is number of fork() statements)
7 are child processes.
 Question 3

A process executes the following code

`for(i=0; i<n; i++) for();`

The total number of child processes created is

 A n B (2n) - 1 C 2n D (2n+1) - 1
Operating-Systems       System-Calls       GATE 2008
Question 3 Explanation:
Fork is a system call, implements in kernel.
It is a operation where process creates a copy of itself.

1,3,7,15,31,... ⇒ 2n-1
 Question 4

Consider the following code fragment:

```  if (fork() == 0)
{ a = a + 5; printf(“%d, %d\n”, a, &a); }
else { a = a – 5; printf(“%d, %d\n”, a, &a); }```

Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?

 A u = x + 10 and v = y B u = x + 10 and v is ≠ y C u + 10 = x and v = y D u + 10 = x and v ≠ y
Operating-Systems       System-Calls       GATE 2005
Question 4 Explanation:
u, v values printed by parent process.
u = a - 5; v be address of a
a = u + 5;
x, y values printed by child process.
x = a + 5; y be the address of a
x = u + 5 + 5; v = y
x = u + 10
 Question 5

System calls are usually invoked by using

 A a software interrupt B polling C an indirect jump D a privileged instruction
Operating-Systems       System-Calls       GATE 1999
Question 5 Explanation:
Software interrupts are implementing device drivers (or) transitions between protected mode of operations, such as system calls.
 Question 6
Which of the following standard C library functions will always invoke a system call when executed from a single-threaded process in a UNIX/linux operating system?
 A sleep B strlen C malloc D exit
Operating-Systems       System-Calls       GATE 2021 CS-Set-1       Video-Explanation
Question 6 Explanation:
• A sleep system call takes a time value as a parameter, specifying the minimum amount of time that the process is to sleep before resuming execution. The parameter typically specifies seconds, although some operating systems provide finer resolution, such as milliseconds or microseconds.
• strlen() is not system call.
• The function call malloc() is a library function call that further uses the brk() or sbrk() system call for memory allocation
• Exit also system call
There are 6 questions to complete.

Register Now