Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Operating System  >  Previous Year Questions: System Call

Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE) PDF Download

Q1: Consider the following code snippet using the fork() and wait() system calls. Assume that the code compiles and runs correctly, and that the system calls run successfully without any errors. (2024 SET 1)
Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)

The total number of times the printf statement is executed is ___
(a) 8
(b) 12
(c) 14
(d) 18
Ans: 
(c)
Sol: The printf statement is executed 14 times. The code repeatedly forks processes inside a while loop. Each iteration doubles the number of processes. Initially, one process prints "hello". After each fork, both the parent and child processes print "hello". The loop iterates three times, resulting in 2^3 = 8 processes. Additionally, two processes from the previous iteration wait for each other before proceeding. Thus, the total count is 8 + 4 + 2 = 14 "hello" messages printed before the loop terminates.

Q2: Which one or more of the following options guarantee that a computer system will transition from user mode to kernel mode?  (2023) 
(a) Function Call
(b) malloc Call
(c) Page Fault
(d) System Call
Ans: 
(c, d)
Sol: 
A. function call: functions may be user defined so It also does not guarantee to switch from user to kernel mode.
B. Malloc () call: It can be done in both user and kernel modes. Hence, It cannot guarantee switching.
C. Page fault : When a page fault occurs, required page must be loaded from secondary to main memory. It will be done in privileged mode and guarantee user mode to kernel mode switching.
D. System call : System calls are executed  in kernel mode only. It definitely guarantee switching.
Hence Ans is C,D

Q3: 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?  (2021 SET 1)
[MSQ]
(a) exit
(b) malloc
(c) sleep
(d) strlen
Ans: 
(a, c)
Sol: 
System calls are used to get some service from operating system which generally requires some higher level of privilege.
This question uses two important words “always” and “standard C library functions”.
Let’s check options

  1. exit- This is a function defined in standard C library and it always invokes system call every time, flushes the streams, and terminates the caller.
  2. malloc – This is a function defined in standard C library and it does not always invoke the system call. When a process is created, certain amount of heap memory is already allocated to it, when required to expand or shrink that memory, it internally uses sbrk / brk system call(this does not happen every time) on Unix/Linux. i.e., not every malloc call needs a system call but if the current allocated size is not enough, it’ll do a system call to get more memory. 
  3. sleep- This is not even  standard C library function, it is a POSIX standard C library function. Unix and Windows uses different header files for it. Now as question has said the following standard C library function, let’s consider it as that way. Yes it always invokes the system call .
  4. strlen – This is a function defined in standard C library and doesn’t require any system call to perform its function of calculating the string length. 

Answer : A,C

Q4: The following C program is executed on a Unix / Linux system:  (2019)
Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)

The total number of child process created is __________ .
(a) 31
(b) 63
(c) 5
(d) 6
Ans: 
(a)
Sol: 
Answer is 31
Fork is called whenever i is even, so we can re-write the code as
Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)
fork() will be called 5 times( i = 0, 2, 4, 6, 8, )
∴Total number of process 25= 32
Total number of child process would be 25 - 1 = 31

Q5: Identify the correct order in which a server process must invoke the function calls accept, bind, listen, and recv according to UNIx socket API.  (2015 SET 2)
(a) listen, accept, bind, recv
(b) bind, listen, accept, recv
(c) bind, accept, listen, recv
(d) accept, listen, bind, recv
Ans:
(b)
Sol: Answer: (B)
Bind: Binds the socket to an address
Listen: Waits for connections to the socket
Accept: Accepts a connection to the socket
Recv: Receives data from connection
From Man page of accept:
It extracts the first connection request on the queue of pending connections for the listening socket, creates a  new connected socket,  and returns a new file descriptor referring to that socket.  The newly created socket is not in the listening state. The original socket is unaffected by this call.

Q6: A process executes the code  (2012)
fork();
fork();
fork();
The total number of child processes created is
(a) 3
(b) 4
(c) 7
(d) 8
Ans:
(c)
Sol: 
At each fork() the no. of processes becomes doubled. So, after 3 fork calls, the total no. of processes will be 8. Out of this 1 is the parent process and 7 are child processes. So, total number of child processes created is 7.

Q7: Consider the execution of the following commands in a shell on a Linux operating system.  (2008)
bash$ cat alpha
Mathematics
bash$ In alpha beta
bash$ rm alpha
bash$ cat >> beta << SAME
Information Technology
SAME
bash$ cat beta
The output of the last command will be:
(a) Mathematics Information Technology SAME
(b) Mathematics Information Technology
(c) Information Technology
(d) Information Technology SAME
Ans: 
(d) 


Q8: A process executes the following code  (2008) 
for (i = 0; i < n; i + +) fork( );
The total number of child processes created is
(a) n
(b) 2 n − 1
(c) 2 n 
(d) 2 n + 1 − 1
Ans: 
(b)
Sol:
Each fork() creates a child which start executing from that point onward. So, number of child processes created will be 2− 1.
At each fork, the number of processes doubles like from 1 - 2 - 4 - 8... 2nOf
these except 1, all are child processes.

Q9: A client process P needs to make a TCP connection to a server process S. Consider the following situation: the server process S executes a socket(), a bind() and a listen() system call in that order, following which it is preempted. Subsequently, the client process P executes a socket() system call followed by connect() system call to connect to the server process S. The server process has not executed any accept() system call. Which one of the following events could take place?  (2008)
(a) connect() system call returns successfully
(b) connect() system call blocks
(c) connect() system call returns an error
(d) connect() system call results in a core dump
Ans:
(c)
Sol:  
First thing to note: All the sockets are by default in BLOCKING mode. What do we mean by blocking ??
Blocking mode means that when we make a system call, it blocks the caller for the time "when call() is made till the job is done OR an error returns ". We can set each socket to Non-blocking explicitly. Setting to Non-Blocking means we are telling the kernel that "If the system call cant be completed without putting process to sleep then DON'T put the process to sleep . Instead return with an ERROR immediately and continue the process" which can be checked for the completion by the caller in between the execution of other tasks.
Now coming to this question:
Suppose connect() is in default blocking mode then calling connect() sends SYN packet to the server. Since server has not executed any accept() call it can not acknowledge the SYN packet. Connect() in blocking mode keep sending SYN packets at fixed intervals(first after 6 sec, second after 24 sec typically until 75 sec latest). This is done until an error ETIMEDOUT is returned by the TCP.(in this case, else there are several other type of errors returned in case No port exists for that connection or server id not listening etc.)
Here, option (B) saying that connect() blocks is not entirely wrong but since we know that accept() call is not made by server, connect() WILL NOT WAIT FOREVER and SO IT CAN NOT BLOCK. It will ultimately return with an ERROR message.
So, option (C) is CORRECT.
Core dump thing I don't know about!
But once connect() returns error that socket can not be reused and must be CLOSED.
And a non-blocking connect() is never blocked and immediately returns with an error if connection is not successful although IT CONTINUES WITH TRYING TO CONNECT .Error here just means that it returns a message saying "I could not connect immediately BUT i am trying AND you can check it in between.
Hope it clears a bit


Q10: Which of the following system calls results in the sending of SYN packets?  (2008)
(a) socket
(b) bind
(c) listen
(d) connect
Ans: 
(d)
Sol: 

  • socket( ) creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it.
  • bind( )is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address.
  • listen( ) is used on the server side, and causes a bound TCP socket to enter listening state.
  • connect( ) is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection.

When connect( ) is called by client, following three way handshake happens to establish the connection in TCP.

  1. The client requests a connection by sending a SYN (synchronize) message to the server.
  2. The server acknowledges this request by sending SYN-ACK back to the client.
  3. The client responds with an ACK, and the connection is established.


Q11: The contents of the text file t1 txt containing four lines are as follows :  (2007)
a1 b1
a2 b2
a3 b2
a4 b1
The contents of the text file t2 txt containing five lines are as follows :
a1 c1
a2 c2
a3 c3
a4 c3
a5 c4
Consider the following Bourne shell script :

Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)

Which one of the following strings will NOT be present in the output generated when the above script in run? (Note that the given strings may be substrings of a printed line.)
(a) "b1 c1"
(b) "b2 c3"
(c) "b1 c2"
(d) "b1 c3
Ans: 
(c)

Q12: A user level process in Unix traps the signal sent on a Ctrl-C input, and has a signal handling routine that saves appropriate files before terminating the process. When a Ctrl-C input is given to this process, what is the mode in which the signal handling routine executes?  (2005)

(a) User mode
(b) Kernel mode
(c) Superuser mode
(d)Privileged mode
Ans: 
(a)
Sol: 

  • When an user send an input to the process it can not be in privileged mode  as it is coming from an user so option D , Privileged mode can not be possible here ..

Now see , kernel mode = Privileged mode 

  • That means both option B and option D are equal. As option D can not be possible , option B also false.
  • There is nothing called  superuser mode so option C is clearly wrong .
  • Only option A is left , when an user input come like ' ctrl+ c' the signal handling routine executes in user mode only as a user level process in UNIX traps the signal.

Hence option A is correct answer.

Q13: The shell command  (2005)
find -name passwd -print
is executed in /etc directory of a computer system running Unix. Which of the following shell commands will give the same information as the above command when executed in the same directory?
(a) ls passwd
(b)cat passwd
(c)  grep print passwd
(d)  grep name passwd
Ans:
(d)
Sol: The correct option is D grep name passwd
Grep is a unix command which can be used to find file names with a watching string.

Q14: A student wishes to create symbolic links in a computer system running Unix. Three text files named "file 1", "file 2" and "file 3" exist in her current working directory, and the student has read and write permissions for all three files. Assume that file 1 contains information about her hobbies, file 2 contains information about her friends and file 3 contains information about her courses. The student executes the following sequence of commands from her current working directory.  (2005)
 ln -s file 1 file 2
ln -s file 2 file 3
Which of the following types of information would be lost from her file system?
I. Hobbies
II. Friends
III. Courses
(a) I and II only
(b) II and III only
(c) II only
(d) I and III only
Ans: 
(b)
Sol:  
Correct option: B
 As ln -s is a symbolic link. In this case
File 3 ⇒ File 2  ⇒ File  ⇒ 1Hobbies (actual data).
So File2 and File 3contents are lost.


Q15: Consider the following code fragment:  (2005)
Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)

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 != y
(c) u + 10 = x and v = y
(d) u + 10 = x and v != y
Ans: 
(c)
Sol: 
The correct option is C u + 10 = x and v = y
Fork ( ) returns 0 is child process and process ID of child process is parent process.
In child (x), a = a + 5
In paraent (u), a = a -5
Therefore, x = u + 10
The physical addresses of parent and child processes will be different but our program access virtual addresses. The child process gets an exact copy of parent process and virtual address of ‘a’ doesn’t change in child process, Therefore v = y.

 

The document Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Previous Year Questions: System Call - Operating System - Computer Science Engineering (CSE)

1. What is a system call in computer science?
Ans. A system call is a request made by a program to the operating system for a service, such as reading or writing a file. It is a way for user-level programs to interact with the kernel.
2. How does a system call work in a computer system?
Ans. When a program makes a system call, it triggers a switch from user mode to kernel mode, allowing the operating system to perform the requested operation on behalf of the program. Once the operation is complete, control is returned to the user program.
3. What are some common examples of system calls in operating systems?
Ans. Some common examples of system calls include open, close, read, write, fork, exec, and exit. These system calls allow programs to perform essential functions such as file operations, process creation, and termination.
4. How are system calls different from library functions in programming?
Ans. System calls directly interact with the operating system, while library functions are higher-level functions provided by libraries. System calls require a switch to kernel mode and have higher overhead compared to library functions.
5. Why are system calls important in computer science and operating systems?
Ans. System calls provide a way for user programs to access the services and resources of the operating system, enabling tasks such as file I/O, process management, and communication. They are essential for the functioning of an operating system and for enabling applications to interact with the underlying hardware.
10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Extra Questions

,

video lectures

,

pdf

,

Summary

,

MCQs

,

Previous Year Questions with Solutions

,

past year papers

,

practice quizzes

,

Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)

,

Important questions

,

Objective type Questions

,

Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)

,

mock tests for examination

,

study material

,

ppt

,

shortcuts and tricks

,

Sample Paper

,

Free

,

Exam

,

Semester Notes

,

Viva Questions

,

Previous Year Questions: System Call | Operating System - Computer Science Engineering (CSE)

;