You are on page 1of 11

THE TEST ON CS

TimeLeft=0:-2:40
1 Write a program which can take the following type
of command: "ls | wc ?l" from the user and display
the output to the user. You do not have to implement
"ls" and "wc", you should invoke these programs
which are already available on every system.

This program is to be written on the unix system and
not in OES. ?

4 Mark
2
What will be the output of the following two
programs when they are used in the fashion given
below? How many new 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);
Page 1 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
}
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
");
} ?

4 Mark
3
//There are two threads in a program and they are
trying to manipulate a global variable
simultaneously. Give comments on this program.

int gvar = 0;
mutex gmx;

void * thred1(void * thr_p) {
mutex_lock(&gmx);
int i = 0;
Page 2 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
gvar=0;
while (i++ < 200)
{
gvar++;
}
mutex_unlock(&gmx);
return (NULL);
}


void * thred2(void * thr_p) {
mutex_unlock(&gmx);
mutex_lock(&gmx);
int i = 0;
gvar=8192;
while (i++ < 200)
{
gvar++;
}
pthread_unlock(&gmx);
return (NULL);
}


int main()
{
create thread - routine thred1()
create thread - routine thred2()
} ?

4 Mark
Page 3 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
4 //There are two threads in a program and both of
them are using the same start routine. What conflict
do you see here?


//thread start routine
void * startthread(void * thr_p) {
int i = 0;
int pinput = *((int *) thr_p);
while (i++ < pinput) {
printf("i : %d, input value: %d
", i, pinput);
sleep(1);
}
return ((void *) NULL);
}


int main()
{
int thread1input = 10;
int thread2input = 100;
create thread 1 with start routine startthread() and
parameter thread1input
create thread 2 with start routine startthread() and
parameter thread2input
} ?

5 Mark
5
Create two programs Client and Server. They
communicate using two FIFOs. The client sends a
Page 4 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
text message: "Initiate_Dialog" to the server on one
FIFO and waits for response from the Server on
another FIFO. After receiving the response, client
sends the "Terminate_Dialog" message to the server
and again waits for a response from Server.

The Server sends the response: "ACK" to the Client
for both the "Initiate_Dialog"/"Terminate_Dialog"
messages.

The client waits for a response from server for only
1.5 seconds and if it does not receive the response it
resends the message. The resending of a message is
not done for more than 5 times. The client exits if
does not get a response from the Server after sending
a messsage 5 times. ?

4 Mark
6
By looking at he following code, please tell how
many times "child" will be printed on the screen:

#include < stdio.h>
#include < sys/types.h>
#include < unistd.h>
int main()
{
pid_t pid;
int childstatus;
pid = fork();
if (pid == 0) {
pid = fork();
Page 5 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
if (pid == 0)
{
printf("child
");
}
}
else {
pid = wait(&childstatus);
}
return 1;
} ?
2 4Marks
4
0
1
7 Write a program to open a file in RDWR mode and
read the characters from the file and append the the
same in the same file. ?

4 Mark
8
//Please look at the following program (including
main() and factorial()) Here main calls factorial with
number = 5. When would the run-time stack assume
the biggest size and what will be there on the stack at
that time?



int factorial(int number)
{
Page 6 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
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;
} ?

4 Mark
9 Consider the following situation:a process sets a
function called sig_int to be the signal handler for
SIGINT.It then execs a program.Will sig_int remain
the signal handler for SIGINT in the execed
program. ?
Yes 3Marks
No
None of the above
all of the above

Page 7 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
10 What will be the output if the following program is
compiled, linked and executed? How many new
processes will be 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;
} ?

5 Mark
11 The function of the lseek system call is to position the
disk arm to a particular byte offset in a file ?
True 3 Mark
False
Not Answer
Page 8 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
12 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;
} ?
0 4Marks
4
1
2
13
When a process opens a file , the file offset for the
Page 9 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302
position of the next I/O Operation is kept in ?
File Table 3Marks
Inode Table
Vnode Table
User File Descriptor Table

14 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.o?, ?
z.o?, ?u.o?, ?v.o?). What is the expected size of the
executable and why? ?

8 Mark
15
Create 2 threads where one thread continually (in an
infinite loop) accepts input strings from the user and
Page 10 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302




the other thread displays the same string (again in
an infinite loop). Thread 1 should be able to accept
up to five strings at a time. After every input Thread
2 should display the same string. ?

4 Mark
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
compilation-linking time
2. All local variables are created in an area of the
executable file called 'stack' area at the compilation-
linking time ?
Both are false 5Marks
1 is true and 2 is false
1 id false and 2 is true
Both are true

submit
Page 11 of 11
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=485&s2=20302

You might also like