System-Calls

Question 1

System calls are usually invoked by using

A
a software interrupt
B
polling
C
an indirect jump
D
a privileged instruction
Question 1 Explanation: 
Software interrupts are implementing device drivers (or) transitions between protected mode of operations, such as system calls.
Question 2

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
Question 2 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 3

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
Question 3 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 4

A process executes the code

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

The total number of child processes created is

A
3
B
4
C
7
D
8
Question 4 Explanation: 
The no. of child process created = 2n - 1 = 23 - 1 = 7 (where n is number of fork() statements)
7 are child processes.
Question 5
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
Question 5 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
Question 6

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
Question 6 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 7
Assuming that the system call fork () never fails, consider the following C programs P1 and P2 executed on a UNIX/ Linux system:

Statement I: P1 displays “Happy” 8 times.
Statement II: P2 displays “Happy” 12 times.
In the light of the above statements, choose the correct answer from the options given below:
A
Both Statement I and Statement II are true
B
Both Statement I and Statement II are false
C
Statement I is correct but Statement II is false
D
Statement I is incorrect but Statement II is true
Question 7 Explanation: 
As we know that “n” fork calls will lead to 2n-1child processes. Hence Total no. of process will be 2n-1+1(We added 1 for the parent process).
Now since in P1 all 3 fork calls are done before the printf statement so all 8( 23-1+1) processes will execute the Printf statement. Hence in P1 Printf statement will be executed for 8 times.
There are 7 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access