0% found this document useful (0 votes)
2 views

OS_Lab_Exam_MCQ_Questions_All_20

The document contains a series of operating systems lab exam questions and answers covering topics such as process creation, scheduling algorithms, memory management, threading, and system calls. Each question presents a code snippet or scenario, followed by multiple-choice answers with the correct answer indicated. The questions assess knowledge of fundamental operating system concepts and programming in C.

Uploaded by

Ananya Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

OS_Lab_Exam_MCQ_Questions_All_20

The document contains a series of operating systems lab exam questions and answers covering topics such as process creation, scheduling algorithms, memory management, threading, and system calls. Each question presents a code snippet or scenario, followed by multiple-choice answers with the correct answer indicated. The questions assess knowledge of fundamental operating system concepts and programming in C.

Uploaded by

Ananya Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Operating Systems Lab Exam Questions

1. Q1. What will be the output of the following code?


#include <stdio.h>
#include <unistd.h>
int main() {
fork();
printf("OS\n");
return 0;
}

 A. OS
 B. OS OS
 C. Compile error
 D. Runtime error

Answer: B

2. Q2. What does the following program simulate?


#include <stdio.h>
#include <stdlib.h>
int main() {
int pid = fork();
if (pid > 0)
sleep(10);
else
exit(0);
}

 A. Orphan process
 B. Zombie process
 C. Deadlock
 D. Parent-child loop

Answer: A

3. Q3. What is the correct behavior of this wait() function?


#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
int main() {
int pid = fork();
if (pid == 0)
printf("Child\n");
else {
wait(NULL);
printf("Parent\n");
}
}

 A. Parent executes first


 B. Child executes first, then parent
 C. Both at the same time
 D. Infinite wait

Answer: B

4. Q4. What is the function of exec() in the context below?


#include <unistd.h>
int main() {
char *args[] = {"/bin/ls", "-l", NULL};
execv(args[0], args);
return 0;
}

 A. Creates a new process


 B. Replaces current process image
 C. Terminates process
 D. Lists all processes

Answer: B

5. Q5. What does this Round Robin scheduling simulation represent?


struct Process {
int pid, bt, rt;
};

 A. SJF scheduling
 B. FCFS scheduling
 C. Round Robin scheduling
 D. Priority Scheduling

Answer: C
6. Q6. Identify the correct scheduling logic in this snippet:
for (int i = 0; i < n; i++)
if (arrival[i] < arrival[min] && !completed[i])
min = i;

 A. FCFS
 B. Round Robin
 C. Priority Scheduling
 D. SJF Non-preemptive

Answer: D

7. Q7. What will this shared memory code do?


int shm_id = shmget(IPC_PRIVATE, 1024, IPC_CREAT | 0666);
char* str = (char*) shmat(shm_id, NULL, 0);
strcpy(str, "Hello Shared Memory");

 A. Writes to a file
 B. Writes to stack
 C. Writes to shared memory segment
 D. Writes to socket

Answer: C

8. Q8. What happens in the following multithreading code?


pthread_t t;
pthread_create(&t, NULL, NULL, NULL);

 A. Compiles and runs


 B. Compilation error
 C. Segmentation fault
 D. Thread prints message

Answer: B

9. Q9. In this producer-consumer code, what is the role of the semaphore?


sem_wait(&empty);
// critical section
sem_post(&full);

 A. Ensure atomicity
 B. Handle memory allocation
 C. Manage CPU scheduling
 D. Prevent deadlock

Answer: A

10. Q10. Which of the following memory allocation strategy does this simulate?
int memory[5] = {100, 500, 200, 300, 600};
// Logic: allocate to the first block that fits

 A. Best-Fit
 B. First-Fit
 C. Worst-Fit
 D. Paging

Answer: B

11. Q11. Which of these is a result of not releasing mutex properly in threads?
pthread_mutex_lock(&m);
// critical section without unlock

 A. Deadlock
 B. Race condition
 C. Compilation error
 D. Nothing

Answer: A

12. Q12. What will this shell command executed via system() do?
system("touch test.txt");

 A. Removes file
 B. Creates empty file
 C. Edits file
 D. Lists files

Answer: B

13. Q13. What does this paging algorithm represent?


for (i = 0; i < n; i++) {
if (page[i] not in frame) {
replace using FIFO logic
}
}

 A. Optimal
 B. LRU
 C. FIFO
 D. Clock

Answer: C

14. Q14. What happens if this C file handling code tries to read a non-existent file?
FILE *f = fopen("data.txt", "r");

 A. Creates file
 B. Returns NULL
 C. Crashes
 D. Infinite loop

Answer: B

15. Q15. What will be printed by this thread function?


void* print(void* arg) {
printf("%s\n", (char*)arg);
return NULL;
}
pthread_create(&t, NULL, print, "Threading");

 A. Error
 B. Threading
 C. %s
 D. Nothing

Answer: B

16. Q16. What does this shell command from C do?


system("ps -e");

 A. Kills processes
 B. Lists all running processes
 C. Starts processes
 D. Compiles code
Answer: B

17. Q17. What will happen in this deadlock code?


pthread_mutex_lock(&m1);
pthread_mutex_lock(&m2);
// ...
pthread_mutex_unlock(&m2);
pthread_mutex_unlock(&m1);

In another thread:
pthread_mutex_lock(&m2);
pthread_mutex_lock(&m1);

 A. Compiles
 B. Runtime error
 C. Deadlock possibility
 D. No issue

Answer: C

18. Q18. What is the output of this command used inside a C program?
system("ls > list.txt");

 A. Deletes list.txt
 B. Writes directory listing to list.txt
 C. Shows directory on screen
 D. Crashes system

Answer: B

19. Q19. Which of the following is a valid way to terminate a process in C?

 A. exit()
 B. kill(pid, SIGTERM)
 C. abort()
 D. All of the above

Answer: D

20. Q20. Which system call creates a new process in Linux?


 A. fork()
 B. clone()
 C. exec()
 D. Both A and B

Answer: D

You might also like