Vous êtes sur la page 1sur 18

THE TEST ON CS _______

(1) By looking at the folloing code tell how many times "child" will be printed #include < stdio.h> #include < sys/types.h> #include < unistd.h> int main() { pid_t pid; int childstatus; pid = fork(); if (pid == 0) { fork(); pid = fork(); if (pid == 0) { printf("child"); } } else { pid = wait(&childstatus); printf("process id of child %d", pid); } return 1; }?
1 2 4 0

(2) Consider the following scenario, You can assume a unix machine like Linux. There are five object files: x.o, y.o, z.o, u.o & v.o (each of size 1 KB) x.o contains the main() function y.o contains functions: yf1(), yf2() //function size 512 bytes z.o contains functions: zf1(), zf2() //function size 512 bytes u.o contains function: uf1() //function size 1 KB v.o contains functions: vf1(), vf2() //function size 512 bytes main() calls functions yf1() and uf1(), yf2() calls zf1(), zf1 calls zf2(), zf2() calls vf1().

The executable is created by linking ?x.o? with individual *.o files, i.e. (by linking with ?y.v.o?). What is the expected size of the executable and why? ?
v.o contains 2 functions of 512 bytes each... so,the size of v.o will be 1KB. u.o contains 1 function of size 1KB.. so,the size of u.o will be 1 KB z.o contains 2 functions of size 512 bytes each.. so,the size of z.o will be 1KB y.o contains 2 functions of size 512 bytes each.. so,its size would be 1KB. they are of 1KB each. x.o contains main.main is of size 3Kb and 512 bytes. executable is created by linking all object files individually...so,the expected size would be 7KB and 512 bytes

PR Attribute ID Marks New Marks OS_7 3 2.5 CA_1 2 2

(3) //Please look at the following program (including main() and factorial ()) Here main calls factorial with number = 5. When would the runtime stack assume the biggest size and what will be there on the stack at that time? int factorial(int number) { int factorialval = 0; if (number == 0) { factorialval = 1; } else { factorialval = number*factorial(number-1); } return factorialval; } int main () { int number = 5; int factorialvalue = 0; factorialvalue = factorial(number); return 1; }?
run time stack will assume the biggest size when factorial(0) will be called. at that time,it will contain all the activation records of factorial(),starting from (5),then factorial(4),factorial(3),factorial(2),factorial(1),and finally factorial(this is because factorial() is being called recursively.

when factorial(0)'s stack frame will be created,it will contain its own local variables:factorialval and argument number as 0,and all the above mentioned activation in main(),number is being initialized to 5,and factorialvalue to 0.then factorial(called...so,factorial(5)'s stack frame is created with its local variables,and argument. in factorial(5),control will go to else part,so,again factorial(4) will be called frame created. this process goes on till factorial(0) is called,wherein,factorialvalue=1 will be then every factorial() will return and thus stack size will decrease then.

(4) What will be the output if the following program is compiled, linked and executed? How many created by this program? int main() { pid_t pid; int childstatus; pid = fork(); if (pid == 0) { pid = fork(); if (pid == 0) { printf("child ");
Page 3 of 12 2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=485&s2=20350

} } else { pid = wait(&childstatus); printf("process id of child %d", pid); } return 1; }?


output:: child process id of child 123456 (assuming pid of child is 123456) this is the output in the case,where child executes first...but even if parent process first,wait() will make it wait and control will go to child process...so,output will in main(),pid has been declared as a variable of type pid_t,childstatus a variable then,a fork() has been called...this will create a new child process,C1 for currently process,P1. fork() returns 2 values.to the new created process,i.e child C1,it returns 0 and to process,it returns process id of the child. control goes to first if() statement. if(pid==0) means,child C1 is executing now.

so,control goes to pid=fork()...this will create a new process for currently executing for C1. so,a new child process,C2 is created for child process C1. flow goes to if(pid==0),this means,C2 is executing now. so,child will be printed on console. control goes out of if loop of C2,this means C2 terminates and then from if() of C1,terminates. control goes to else part now...i.e,now the parent process,P1 will execute.wait() status of child process C1 after its termination. and then printf statement will execute. then parent process,P1 terminates.

PR Attribute ID Marks New Marks OS_2 3 3 OS_11 2 2

(6) The function of the lseek system call is to position the disk arm to a particular byte offset in True
False Not Answer

(7) Consider the following situation:a process sets a function called sig_int to be the signal handler xecs a program.Will sig_int remain the signal handler for SIGINT in the execed program. None of the above
No Yes all of the above

What will be the output of the following two programs when they are used in the fashion given w processes will be created by these programs? //file q1.c - executable file "q1" was created by gcc main() { pid_t pid; int lcounter = 0; int exitstatus = 0;
Page 5 of 12 2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=485&s2=20350

(8) execlp("./q6", "q6", NULL); pid = fork(); if (pid == 0) { execlp("./q6", "q6", NULL); } else { pid = wait(&exitstatus); printf("child process id %d ", pid);

} return 1; } //file q6.c - executable file "q6" was created by gcc main() { printf("in q6 "); }?
assuming q1 executes first... output:: in q6 the output is so because... control goes to main() of q1 first. here,pid is a variable of type pid_t.lcounter and exitstatus are integer variables initialized to 0. then control goes to execlp("./q6","q6",NULL) as soon control goes to this execlp(),it replaces the existing process and starts this is because,execlp replaces the code section of currently executing process with executable passed in it. so,all the other statements,which are there after execlp() won't be executed,and now execute. so,after getting execlp(),control goes to q6,and in q6 is printed on console. only,currently executing process's PCB would be there,i.e of q1. after execlp(),though it replaces the currently executing process but it doesn't create process. so,only one process is there(this is currently executing process,q1).no new process PR Attribute ID Marks New Marks

(10) When a process opens a file, the file offset for the position of the next I/O Operation is kept
User File Descriptor Table Vnode Table File Table Inode Table

By looking at he following code, please tell how many times "child" will be printed on the #include < stdio.h> #include < sys/types.h> #include < unistd.h> int main() { pid_t pid; int childstatus; pid = fork(); if (pid == 0) {

(11) pid = fork(); if (pid == 0) { printf("child "); } } else { pid = wait(&childstatus); } return 1; }?
4 2 1 0

(16) Please consider the following two statements and select the correct options: 1. All global objects are created in an area of the executable file called the 'data' area at the 2. All local variables are created in an area of the executable file called 'stack' area at the compilation
1 is true and 2 is false 1 id false and 2 is true Both are false Both are true

(1) "close()" system call is used to delete a file from the file system ?
True False Not Answer

(2) A process has an address space which it can't transgress (jump out of) without making a system
True False Not Answer

(3) In Unix The "dup" function returns the "lowest numbered free entry in the user file descriptor True
False Not Answer

(4)

How many new processes will be created (forked) by the following piece of code: int main() { pid_t pid; int lindex = 0; pid = fork(); if (pid == 0) { printf("child %d", lindex); fork(); } else { while(lindex++ < 10) { printf("parent %d", lindex); } } return 1; }?
4 1 2 0

(5) A parity bit is?


is the last bit in a byte used to indicate uppercase letters used to detect errors is the first bit in a byte

(6) During context switch, CPU does not do any useful work as far as program execution is concerned
True False Not Answer

(7) Please look at the following structure of the directory ("/user/gur55555") and select the correct directories: "src", "obj", "bin" regular files: "makefile" files in subdirectory "src": x.c, y.c, z.c files in subdirectory "obj": x.o, y.o, z.o files in subdirectory "bin": a.out ?
directory file "/user/gur55555" will contain a table having 3 entries : 1. {{"src", indode_1}, 2. {"obj", indode_2},

3. directory file "/user/gur55555" will contain a table having 11 entries for all regular files and subdirectories (directory file "/user/gur55555" will contain a table having 4 entries {{"src", indode_1}, {"obj", indode_2}, indode_4}, } x b Directory file "/user/gur55555" will contain a table having 1 entry {{"makefile", indode_1}}

(10) "Open()" system call can be used to open a file as well as create a file. ?
True False Not Answer

(11) What happens when a parent process terminates before the termination of a child process ?
The child process is marked as zombie. Swapper becomes the parent of the running child The parent process id of the child is changed to 1 The parent process id of the child is changed to 0

(12) readdir() is a system call, which can be used to read a directory file ?
True False Not Answer

(13) signal() system call is used to attach a signal handler function to a signal ?
True False Not Answer

(14) On-Chip Cache has ?


larger capacity than off chip cache become obsolete its own data bus lower access time than RAM

(15) What will be the output of the following program? How many new processes will be created? int main() { pid_t pid; int childstatus; pid = fork();

if (pid == 0) { fork(); fork(); printf("child"); } else { pid = wait(&childstatus); printf("process id of child %d", pid); } return 1; }?
OUTPUT: CHILD CHILD CHILD CHILD PROCESS ID OF CHILD (SOME PCS ID OF THE FIRST CHILD) EXPLANATION: here at line pid = fork() main creates a CHILD(1) then in that child: again at fork() this CHILD(1) creates another GRAND then again at fork() ,CHILD(1),GRAND CHILD(2) creates both the process are creating a child each therefore one GRAND CHILD(3) and one GRAN_GRAND CHILD(4) are created after that printf("child") statement is executed processes which are CHILD(1),GRAND CHILD(2),GRAND CHILD(3) AND GRAND-GRAND CHIDL(4), times child is printed on the screen After that in parent of the CHILD(1) i.e. is main ,it is waiting for it to terminate (" "); i.e. prints process id of child and some procees id of CHILD(1) is printed NO. OF NEW PROCESSES ARE : 4 AND ONE MAIN PROCESS IS ALREADY THERE

PR Attribute ID Marks New Marks OS_11 2 1.8 OS_2 3 2.9

(16) A computer that uses 32 - bit registers stores hex value 1234 at address 0.The data stored endian format at address locations 00 01 10 11 are ?
00 00 12 34 34 12 00 00 12 34 00 00 00 12 34 00

(18) The address space of a running program is typically divided into following areas: Text, data, u please explain what do you keep where with examples from the following program? Every d.

//File x.c int globalvar = 0; char * samplefunc(int lparam) { char * pchar = NULL; if (lparam == 1) { pchar = (char *) malloc(11); strcpy(pchar, "samplefunc"); } return pchar; } int main() { char lchar = 'a'; char * pcharmain = NULL; int param = 1; pcharmain = samplefunc(param); if (globalvar == 0) printf("%s : %c", pcharmain, lchar); }?
CODE STARTS: int globalvar = 0; globalvar is stored in data area main() { char lchar = 'a'; --> lchar is stored in stack area char *pcharmain = NULL;--> stored in heap area int param = 1;-->param is stored in stack area pcharmain = samplefunc(param);-->stored in etxt area of code and stack is modified adrress of functiuon and its first instruction addr and its paramete passed then in function()--> char *pchar=NULL-->sotred in heap area if(lparam ==1)--> code text stored in text area { pchar = (char*)malloc(1);-->memory form heap area ,therefore in heap area strcpy(pchar,"samplefunc")-->text area } return pchar--> returns to main function and then the stack is modifed as the first be executeed after return is there and all the stack for funtion is deleted and then paramete i.e is return value etc are overwritten if(glabalvar==0)-->text area printf("%s:%c",pcharmain,lchar);---->text area

PR Attribute ID Marks New Marks CA_1 5 3

(19) Which program segment at run time is used to store interrupt and subroutine(funtion) return

Extra segment Code Segment Data Segment Stack Segment

(20) Please look at the following code and select the correct option //file.c int globalobj; int main { char * pobj; int lobj; pobj = malloc(10); }?
none of the options are true lobj will go into stack and pobj would go into heap lobj will be on stack and the object pointed to by pobj would go into heap pobj & lobj would go into stack area

(21) Function call sequence in a program is as follows: int funcA(char a) { //some more code funcB(a); //some more code } int funcB(char b) { //some more code funcC(b); //some more code } int funcC(char c) { //some more code //some more code } Please indicate which of the following possibilities may be correct ?
Address of object 'a' is 0x10000020, Address of object 'b' is 0x10000020, Address of object 'c' is 0x10000020 Address of object 'a' is 0x10000000, Address of object 'c' is 0x10000010, Address of object 'b' is 0x10000020 Address of object 'c' is 0x10000020, Address of object 'b' is 0x10000010, Address of object 'a' is 0x10000000

Address of object 'c' is 0x10000000, Address of object 'a' is 0x10000010, Address of object 'b' is 0x10000020

(22) The function commonly used to return a structure of information about a named file is : ?
chown() stat() s_isdir() s_isreg()

(23) Please consider the following two statements and select the correct options: 1. All global objects are created in an area of the executable file called the 'data' area at the 2. All local variables are created in an area of the executable file called 'stack' area at the compilation
Both are true Both are false 1 id false and 2 is true 1 is true and 2 is false

(26) In Unix environment, if you want to start running a different new program in a new process (i.e., program x from program y), which system calls would you use ?
fork() followed by exec() fork() read() followed by fork() open() followed by fork()

(28) Before getting data or instruction from a main memory location, the CPU always makes the ter to refer to that location. ?
True False Not Answer

(29) Choose the function, which a process uses to synchronize its execution with the termination of its child ?
lstat() signal() wait() exit()

(31) What is the output of the following program code: main() { fork(); fork(); fork();

printf("Hello World"); }?
Hello world will be printed 1times. Hello world will be printed 27 times. Hello world will be printed 3 times. Hello world will be printed 8 times.

THE TEST ON CS _______

(1) Which data structure(s) is used by the UNIX kernel to manage files opened by a process?
Use File Descriptor Table File Table Inode table All of these

(3) Suppose you invoked the command ls -li in your current directory and a portion of the output shows three rows with the same number column.What does it signify ? ?
There are three copies of a directory with inode number 4900520 The observation does not lead to any conclusion There are three copies of a file with inode number 4900520 The number 4900520 is the inode number of a file and the file is having two links.

What will be the output if I run the program q7 as follows: $./q7


Page 1 of 8 2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=456&s2=20440

(4) //file q7.c: It is used to create an executable q7 main() { printf("in q7 "); sleep(1);

execlp("./q8", "q8", NULL); return 1; } //file q8.c: It is used to create an executable q8 main() { pid_t pid; int exitstatus = 0; printf("in q8 "); sleep(1); execlp("./q7", "q7", NULL); pid = fork(); if (pid == 0) { printf("child process "); } else { pid = wait(&exitstatus); printf("parent process "); } return 1; }?
Page 2 of 8 2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=456&s2=20440
When q7 runs, it prints string "in q7" and sleeps for 1 sec. It then calls an execlp call and as a result the text, data, stack and heap area of and text, data, stack and heap areas of q8 are written over it. No new Process is created and process id remains the same. Only register values in PCB are changed. Program counter now points to 1st instruction of q8. It prints string: "in q8" and invokes execlp using q7 and remaining instructions of away. Again stack, data, text and heap of q8 are overwritten and Program counter passes instruction of q7. q7 again prints string :"in q7" and invokes execlp using q8,which again invkoes execlp As a result this leads to infinite loop and CPU is continously engaged serving this in q7 in q8 in q7 in q8 in q7 . . . infinite times.

PR Attribute ID Marks New Marks OS_2 2 1.7 OS_10 4 3.4

(5) The function of the lseek system call is to position the disk arm to a particular byte offset in True
False Not Answer

(6) What will be the output of the program when I run the executable created from it, and how be created by this program when it is executed? There is one particular thing about this piece that out? int main() { pid_t pid; int childstatus; pid = fork(); if (pid == 0) { sleep(1); printf("child "); } else { printf("process id of child %d ", pid); } return 1; }?
One new process will be created by the given program(using fork() system call). In total 2 processes will be running simultaneously. The main() function creates a new child process,thus there are now 2 processes parent child process. fork() call will return pid value=0 in child process and will return Process Id of its parent process. In child process, there is a sleep call,due to which time-slot is given to parent parent process prints the line "process id of child 456252" (ASSUMING process id of child is 456252). The parent terminates before the child and then time-slot is given to the child which string "child" and terminates. The particular thing about this code is that this code produces to ORPHAN child whose terminates before its child.

PR Attribute ID Marks New Marks OS_11 2 1.75 OS_2 3 2.7

(8) What happens when a process having no child process executes a wait call ?
Runtime error may occur . Returns with the termination status of a zombie child. Returns immediately with an error Blocks the process

What will be the output of the following two programs when they are used in the fashion given w processes will be created by these programs? //file q1.c - executable file "q1" was created by gcc main() { pid_t pid; int lcounter = 0; int exitstatus = 0; execlp("./q6", "q6", NULL); pid = fork(); if (pid == 0) { execlp("./q6", "q6", NULL); } (9) else { pid = wait(&exitstatus); printf("child process id %d", pid); } return 1; } //file q6.c - executable file "q6" was created by gcc main() { printf("in q6"); }?
When the executable q1 executes the instruction 'execlp',the stack, heap, data and are washed away and then the stack, heap, data and text portions for the new process(case) are created in the same area which initially contained q1. The process Id of process remains the same. New PCB (Process Control Block) is not formed for q6,but register values are changed program counter points to 1st instruction in q6,i.e. the area in memory which was initially,is overwritten by another process q6 which acts as a container for q6. As a result, instructions following the execlp call in q1 are not executed(because has been overwritten). So no new processes are created by this program. The control goes to 1st instruction in q6 which prints the string:"in q6" and terminates.

PR Attribute ID Marks New Marks OS_11 2 1.65 OS_2 3 2.6

The following program running on a computer can be stopped only through a hardware interrupt rough no software intervention int main() { int a = 0; while (1) { a++; a--; } return 1; }?
True False Not Answer

(11) What will be the output if the following program is compiled, linked and executed? How many created by this program? int main() { pid_t pid; int childstatus; pid = fork(); if (pid == 0) { pid = fork(); if (pid == 0) { printf("child"); } } else { pid = wait(&childstatus); printf("process id of child %d", pid); } return 1;

}?
Page 7 of 8 2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=456&s2=20440
2 new processes are being created by this program. In main(),fork() is used to create a new child process(parent->child). This fork will return pid==0, in child process. Generally time-slot is given to the child, which invokes another fork() call. This fork() creates a new process inside the child(child->child1). By default time-slot passes to child1, which prints the string :"child" and terminates. Time-slot passes to parent i.e. to main() as child has already terminated. Parent gets the exit status of its child and prints its process id and terminates.

PR Attribute ID Marks New Marks OS_2 3 2.6 OS_11 2 1.65 Page 8 of 8 2/6/2009 http://10.203.161.13/OES/take1.jsp?s1=456&s2=20440

Vous aimerez peut-être aussi