OS LAB MCQ Modified
OS LAB MCQ Modified
A. True
B. False
C. May be
A. user
B. kernel
C. supervisory
D. system
A. User
B. kernel
C. supervisory
4. All UNIX and LINUX systems have one thing in common which is ____
B. set of commands
C. set of instructions
A. Write
B. Rd
C. Read
6. Which of the following system call is used for opening or creating a file?
A. Read
B. write
C. open
D. close
A. 4
B. 3
C. 2
8. Which of the following mode is used for opening a file in both reading and writing?
A. O_RDONLY
B. O_WRONLY
C. O_RDWR
A. int
B. float
C. char
D. double
10. Which of the following system call is used for closing a file?
A. Open
B. Lseek
C. Close
D. create
A. 0
B. 1
C. May be
D. 0 or -1
A. read
B. write
C. close
D. seek
14. ____ system call is used for positioning the offset pointer.
A. read
B. write
C. open
D. lseek
15. Which of the following offset is used with lseek system call to set the offset pointer to the end of the
file?
A. SEEK_SET
B. SEEK_END
C. SEEK_CUR
D. SEEK_CR
16. The read system calls return 0 when ………..
C. file is empty
D. none of these
17. When a process makes a system call ,its mode changes from………
A. user to kernel
B. kernel to user
C. restricted to unrestricted
D. unrestricted to restricted
A. print a file
B. display a file
C. capture a file
D. copy a file
19. When the read system call encounters EOF ,it returns
C. 0
D. -1
B. scheduling processes
D. all of these
22. When a process executes a system call, the execution mode of the process changes from
………..
D. none of these
1. Consider a scenario in which one parent process has single child process created by using
pid = fork();
Then the task to be performed only by the child process should be written as:
ans: c
2. A file named "os.txt" already exists in your system. Suppose the text "An operating system
(OS) is system software that manages computer hardware, software resources, and provides
services for computer programs" is written into it. Open this file for reading purpose and
truncate the size to zero.
ans: a
3. Consider a file “F1” having some content already written into it. In order to reposition at
the 10th position from the start which of the code will be used.
a) n=open("F1",O_RDONLY);
lseek(n,10,SEEK_BEG);
b) n=open("F1");
lseek(n,10,SEEK_SET);
c) open("F1",O_RDWR);
lseek(n,10,SEEK_START);
d) n=open("F1",O_RDWR);
lseek(n,10,SEEK_SET);
Ans: d
4. Create a new thread "th_new". Newly created thread executes a non parameterised function
named "function_new".
ans: a
5. Consider a file named "file" having some content. Code to read 13 characters from it and
print all the read characters on screen will be
a.)
char buffer[13];
fd=open("file",O_RDWR);
read(fd,buffer,13);
write(1,buffer,13);
(b)
char buffer[13];
fd=open("file",O_RDONLY);
read(0,buffer,13);
write(1,buffer,13);
(c)
char buffer[13];
fd=open("file",O_RDWR);
read(0,buffer,13);
write(1,buffer,13);
(d)
char buffer[13];
fd=open("file",O_RDWR);
read(fd,buffer,13);
write(fd,buffer,13);
Ans: A
MCQ questions
a) 4
b) 6
c) 8
d) 5
Ans- b
2. Consider the following code
int a=5
int main()
{
int p;
p=fork();
if(p==0){
a+=15;
return 0;
}
else {
wait(NULL);
printf("Parent:value is=%d",a)
return 0;
}
}
What will be the value of ‘a’ printed in parent process?
a) 15
b) 20
c) 5
d) Parent will not execute
Ans-c
Ans-c
4. A file named "test.txt" already exists in your system. Which of the following syntax will be
used to open the file for reading purpose?
a) open("test.txt", O_RDONLY);
b) open("test.txt", O_CREAT|O_RDONLY, 0664);
c) open("test.txt", O_READ);
d) open("test.txt", O_CREATE|O_RDWR);
Ans-a
5. Consider a file named "test" with some content in it. Which of the following options will be
used to read 10 characters from the file and print all the read characters on screen
a.)
char buf[20];
fd=open("test",O_RDWR);
read(fd,buf,10);
write(1,buf,10);
(b)
char buf[20];
fd=open("test",O_RDONLY);
read(0,buf,10);
write(1,buf,10);
(c)
char buf[20];
fd=open("test",O_RDWR);
read(0,buf,10);
write(fd,buf,10);
(d)
char buf[20];
fd=open("test",O_RDWR);
read(fd,buf,10);
write(fd,buf,10);
After running the above code, the input to the code is given as “CSE325 CA”. What will be
the value of ‘n’ printed?
a) 9
b) 20
c) 30
d) 10
Ans-d
Ans-d
8. Assume there is file named as “file.txt”. Currently the permission of a file are: read, write
execute for user, read for group and no permissions for others. What will be used to set the
permissions to read and execute for user, read and write for group and read for others.
a) chmod 764 file.txt
b) chmod 564 file.txt
c) chmod 664 file.txt
d) chmod 561 file.txt
Ans -b
9. Assume there is a file named as “test.txt”. If you want to rename a file to demo.txt. which of
the following command will be used.
a) rename test.txt demo.txt
b) rn test.txt demo.txt
c) mv test.txt demo.txt
d) There is no command to rename a file.
Ans-c
Ans-b
Ans-a
Ans-b
1. read.out
2. a,out
3. read
4. read.c
Ans: 3
int main( )
pid_t p, q;
p=fork();
if(p = = 0)
q=fork();
Ans: 2
3. Consider a scenario in which one parent process has single child process created by using
pid = fork();
Then the task to be performed only by the parent process should be written as:
a) if(pid < 0) { //specify the task}
ans: b
c) -1
d) it returns nothing
Ans: b
c) file descriptor
d) it returns nothing
Ans: c
1234567890
What will be the contents of the file after this code is executed?
int main()
char b[10];
int n;
n=open(“f1”,O_RDWR);
read(n,b,3);
write(n,”OK”,2);
a) OK
b) OK34567890
c) 123OK67890
d) 1234567890
Ans: c
1234567890
What will be the contents of the file after this code is executed?
int main()
char b[10];
int n;
n=open(“f1”,O_RDONLY);
read(n,b,3);
write(n,”OK”,2);
a) OK
b) OK34567890
c) 123OK67890
d) 1234567890
Ans: d
1234567890
What will be the contents of the file after this code is executed?
int main()
{
char b[10];
int n;
n=open(“f1”,O_RDWR);
read(n,b,3);
lseek(n,2,SEEK_CUR);
write(n,b,2);
a) 123
b) 1234567890
c) 1234512390
d) 1234512890
Ans: d
9. A file named "os.txt" already exists in your system. Suppose the text "An operating system
(OS) is” is written into it. The code to open the file for writing “system software” in the end
is
a. int n;
write(n,”system software”,15);
b. int n;
n=open("os.txt", O_RDWR);
write(n,”system software”,15);
c. int n;
write(1,”system software”,15);
d. int n;
n=open("os.txt", O_RDWR);
write(1,”system software”,15);
Ans: a
10. Consider a file “F1” having some content already written into it. In order to reposition
the cursor at the 10th position from the beginning which of the following code will be used.
a) n=open("F1",O_RDONLY);
lseek(n,10,SEEK_BEG);
b) n=open("F1");
lseek(n,10,SEEK_SET);
c) open("F1",O_RDWR);
lseek(n,10,SEEK_START);
d) n=open("F1",O_RDWR);
lseek(n,10,SEEK_SET);
Ans: d
11. Consider a file “F1” having the content “Operating” already written into it. In order to
print “ing” on the screen which of the following code will be used.
a) int n;
char buff[10];
n=open(“F1”, O_RDWR);
read(n,buff,3);
write(1,buff,3);
b) int n;
char buff[10];
n=open(“F1”, O_RDWR);
lseek(n,-4,SEEK_END);
read(n,buff,3);
write(1,buff,3);
c) int n;
char buff[10];
n=open(“F1”, O_RDWR);
lseek(n,-4,SEEK_END);
write(1,buff,3);
d) int n;
char buff[10];
n=open(“F1”, O_RDWR);
lseek(n,4,SEEK_SET);
read(n,buff,3);
write(1,buff,3);
Ans: b
12. Consider a file named "file" having some content. Code to read 13 characters from it and
print all the read characters on screen will be
a.)
char buffer[13];
fd=open("file",O_RDWR);
read(fd,buffer,13);
write(1,buffer,13);
(b)
char buffer[13];
fd=open("file",O_RDONLY);
read(0,buffer,13);
write(1,buffer,13);
(c)
char buffer[13];
fd=open("file",O_RDWR);
read(0,buffer,13);
write(1,buffer,13);
(d)
char buffer[13];
fd=open("file",O_RDWR);
read(fd,buffer,13);
write(fd,buffer,13);
Ans: A
int main()
pid_t p;
p=fork();
if(p==0)
printf(“Child process”);
else
sleep(3);
}
1. zombie process
2. orphan process
3. no child process
Ans: 1
14. The system call used to make the parent process wait for the child process to finish is
1. wait
2. fork
3. system
4. exec
Ans: 1
15. Out the following which header file(s) are required for the fork() system call
1. sys/types.h
2. unistd.h
3. stdio.h
a) only (1)
b) only (2)
Ans: c
16. Consider a directory D1 having a file F1. The command to delete D1 will be
1. rm D1
2. rm -r D1
3. rmdir D1
4. rmdir -r D1
Ans: b
1. Ctrl+x
2. Shift+x
3. Ctrl+q
4. Shift+q
Ans: 1
Ans: 1
19. The system call used to reposition the curson within the file is
1. write
2. read
3. open
4. lseek
Ans: 4
int main()
{
printf(“First Output”);
execl(“\bn\ps”,”ps”,NULL);
printf(“Second Output”):
a) First Output followed by the list of running processes, followed by Second Output
Ans: b
Q21. What will be the value of the variable “f1”. The contents of the file “seeking” are
1234567890abcdefghijx1x2x3x4x5
int n,f,f1;
f=open("seeking",O_RDWR);//1234567890abcdefghijx1x2x3x4x5
f1=lseek(f,10,SEEK_SET);
printf("Pointer is at %d position\n",f1);
a) 10
b) 9
c) 11
d) 1
Ans: a
int main()
{
pid_t p,q;
p=fork();
if(p==0)
fork();
else
fork();
a) 3
b) 4
c) 7
d) 8
Ans: a
Ans: c
2. Which of the following code synipt is correct in order to create 7 child processes of one
parent process
a) int main()
{
fork();
printf("Child Process\n");
return 0;
}
b) int main()
{
fork();
fork();
printf("Child Process\n");
int func1()
{
fork();
fork();
}
return 0;
}
c) int main()
{
fork();
fork();
printf("Child Process\n");
return 0;
}
d) int main()
{
fork();
fork();
fork();
printf("Child Process\n");
return 0;
}
Ans: d
3. Which of the following is correct to read 13 characters from a file named first.txt and write
into another non existing file final.txt.
a) <header files>
<main function>
int first, final, n;
char b[50];
first= open("first.txt", O_RDONLY);
n=read(first,buf,13);
final=open("final.txt", O_CREAT | O_WRONLY);
write(final,buf,n);
b) <header files>
<main function>
int first, final, n;
char b[50];
first= open("first.txt", O_RDONLY);
n=read(first,b,13);
final=open("final.txt", O_CREAT | O_WRONLY);
write(final,b,n);
c) <header files>
<main function>
int first, final, n;
char b[50];
first= open("first.txt", O_RDONLY);
n=read(first,b,13);
final=open("final.txt", O_WRONLY);
write(final,buf,n);
d) <header files>
<main function>
int first, final, n;
char b[50];
first= open("first.txt", O_RDONLY);
n=read(first,b,13);
final=open("final.txt", O_CREAT,O_WRONLY);
write(final,b,n);
Ans: b
Ans: d