MCQs Operating System Lab 80+

1. Input string is 987654321!@#$%^&*()abcdefghij

int main() 
{ 
int x,y,z; 
char b[50]; 
 
x=open("file.txt",O_RDWR); 
y=lseek(x,10,SEEK_SET); 
read(x,b,15); 
write(1,b,20);
} 

The output of the program is:

  • @#$%^&*()abcdef
  • @#$%^&*()abcdefghij
  • Open Error
  • @#$%^&*()

Ans: A

2. How many times hello will be printed?

#include<stdio.h> 
 
#include<sys/types.h> 
 
int main() 
 
{ 
 
Pid_t p; 
 
printf("hello"); 
 
Fork(); 
 
Fork(); 
 
Fork(); 
 
printf("hello"); 
}
  • 16
  • 4
  • 8
  • 32

Ans: C

3. Choose the correct configuration

CommandDescription
IPC_SETDeletes the message queue.
IPC_STATSets the data in the msqid_ds structure to reflect the values associated with the message queue.
IPC_RMIDused to create the shared segment if it does not exist
IPC_CREATIf the process has permission to do so, this sets the values associated with the message queue to those provided in the msqid_ds data structure.
  • B–>D–>A–>C
  • A–>C–>B–>D
  • D–>B–>A–>C
  • B–>C–>A–>D

Ans: A

4. Which of the following statement is correct?

  • pipe() creates a unidirectional stream having two descriptors.
  • popen() creates a unidirectional stream having two descriptors.
  • popen() creates a bidirectional stream having one descriptors.
  • pipe() creates a bidirectional stream having two descriptors.

Ans: A

5. IPC stands for

  • Inter process communication
  • Inter personal communication
  • Internal process connection
  • Internal process communication

Ans: A

6. Which command is used to display the present working directory?

  • pwd
  • Whoami
  • ls -l
  • kernel

Ans: A

7. A file named “test.txt” already exists in your system. Which of the following syntax will be used to create new file “test1.txt ” for writing purposes?

  • open(“test1.txt”, O_READ);
  • open(“test1.txt”, O_RDONLY);
  • open(“test1.txt”, O_CREAT|O_WRONLY, 0732);
  • open(“test1.txt”, O_CREATE|O_RDWR);

Ans: C

8. To check the zombie process which of the following commands will be used?

  • ./a.out & +ps
  • ./a.out + ps
  • ./a.out +ls
  • ./a.out & + pwd

Ans: B

9. Choose the correct statement:

  • Wait and signal operations are part of semaphores
  • Wait and signal operations are part of inter process communication.
  • Wait and signal operations are part of mutex lock.
  • Wait and signal operations are part of threads.

Ans: A

10. The input in file is 987654321!@#$%^&*()abcdefghij

int main() 
 
{ 
 
int x,y,z; 
 
char b[50]; 
 
x=open("file.txt",O_RDWR); 
 
y=lseek(x,-11,SEEK_END); 
 
read(x,b,20); 
 
write(1,b,12);  
 
} 

The output of program is

  • ()abcdefgh
  • ()abcdefghij
  • abcdefghij
  • error in program

Ans: B

11. Mkfifo() creates the pipes by default in

  • Unblocking mode
  • Reading and writing mode
  • Blocking mode
  • Bidirectional mode

Ans: C

12. If exec is called immediately after forking __

  • The program specified in the parameter to exec will replace the entire process
  • All the threads will be duplicated
  • All the threads may be duplicated
  • None of the mentioned

Ans: A

13. A parent process calling _ system call will be suspended until children processes terminate.

  • wait
  • fork
  • exit
  • exec

Ans: A

14. Which of the following statement is false:

  • msgget() function is used to get the data from message queue.
  • msgctl() is a message queue control function.
  • Msgget() is used to create and access a message queue.
  • All of the above.

Ans: D

15. The third parameter of pthread_create() function is

  • Name of the function which thread will execute
  • Id of the thread.
  • Attributes of the thread.
  • Input to the function in the third parameter.

Ans: A

16. Which of the following statement is true?

  • Pipe() creates unidirectional two pipes in which first is used for writing and second for reading.
  • Pipe() creates unidirectional two pipes in which first is used for read and second for writing.
  • Pipe() creates bidirectional one pipes which is used for reading and writing.
  • popen() creates unidirectional two pipes in which first is used for read and second for writing.

Ans: A

17. The output is

int main() 
{ 
pid_t q; 
q=fork(); 
if(q==0) 
    { 
     printf("students"); 
      } 
else 
{ 
 printf("CSE LPU"); 
sleep(15); 
}
}
  • CSE defunct LPU
  • CSE LPU defunct students
  • students CSE LPU
  • studentsCSE LPU

Ans: D

18. The second parameter of pthread_create() function is

  • Name of the function which thread will execute
  • Id of the thread.
  • Attributes of the thread.
  • Input to the function in the third parameter.

Ans: C

19. Which of the following command opens the pipe in writing mode?

  • popen(‘wr’,”wc –c”);
  • popen(‘wc –c’,’w’);
  • popen(‘wc’,’wr’);
  • popen(“w+”,”wc –c”);

Ans: B

20. The output of given program is:

int main() 
{ 
char a[25]; int b; 
 
read(0,a,15); 
 
write(1,a,8); 
 
//printf("The output is %d\n",b); 
} 

Consider input as:1112131415

What will be the output?

  • -1
  • 012131415
  • 11121314
  • 1112131

Ans: C

21. The purpose of creating IPC_CREAT in shmget() is:

  • to create a file
  • to create a pipe
  • to create a shared memory segment
  • none of the mentioned

Ans: C

22. In the system table the process in the below snapshot with is known as:

Ans: Zombie Process

23. Choose the correct description of process management:

Call                             Description
a) p=lseek(fd,offset,whence)     1) Open file reading writing or both
b) S=stat(name, &buff)           2) Read data from file to buffer
c) a=open(file, flag, mode)      3) Write data fom a buffer into a file
d) a=write(fd, buffer,nbytes)    4) Move the file pointer
e) b=read(fd, buffer,nbytes)     5) Get a file status information

Ans: a->4, b->5, c->1, d->3, e->2

Operating System Lab Study Material

https://dextutor.com/courses/operating-system-programs/

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *