Sunteți pe pagina 1din 10

THE TEST ON CS

TimeLeft=0:49:41
1
Please have a look at the code and tell how many
times "child" will be printed:


int main()
{
pid_t pid;
pid = fork();
if (pid == 0) {
fork();
fork();
printf("child");
}
else {
printf("parent");
}
return 1;
} ?
4 4Mark
0
8
2
2
Write a program that creates two timers. One of
them expires every 1 second and the other one
expires every 0.5 seconds. When a particular timer
expires thrice, a message should be displayed. The
message to be displayed for timer1 is timer1 expired
Page 1 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302
and for timer2 is timer2 expired. ?

4Mark
3
Which data structure(s) is used by the UNIX kernel
to manage files opened by a process? ?
Inode table 3Mark
File Table
Use File Descriptor Table
All of these
4
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 3Mark
No
None of the above
all of the above
5
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
Page 2 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302
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? ?

8Mark
6
//Please look at the following piece of code and figure
out what is wrong with it from the byte order
perspective?

//Code starts here
{
int sd = 0;
struct sockaddr_in serveraddress;
socklen_t len;
sd = socket( AF_INET, SOCK_STREAM, 0 );
memset( &serveraddress, 0, sizeof(serveraddress) );
serveraddress.sin_family = AF_INET;
//20001 is the port number on which it binds
serveraddress.sin_port = htons(htons(20001));
//10.203.161.7 is the IP address of the server
serveraddress.sin_addr.s_addr = htonl(inet_addr
("10.203.161.7"));
bind(sd,(struct sockaddr*)&serveraddress,sizeof
(serveraddress));
}
Page 3 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302
//Code ends here ?

4Mark
7
Write a program in which one process reads input
from the user ,writes it to the other process via a
FIFO.The second process translates each uppercase
letter to a lowercase letter and sends the data back to
the first process. ?

4Mark
8
Suppose your process was executing the library
function malloc and at the same time a signal was
delivered for which you have written a signal
handler.In the handler code there is a call to
malloc .What property the malloc function should
have to ensure that no inconsistency of data occurs. ?
Recursive 3Mark
No function should be called within the code of malloc.
None
Malloc needs to access at least one static variable.
9 A 32 - bit processor has ?
32 registers 4Mark
32 Mb of RAM
32 bit bus or 32-bit registers
32 I/O devices
When a parent process waits for a child process to
Page 4 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302
10
exit then the operating system provides the exit
status of the child to the parent. ?
True 3Mark
False
Not Answer
11
The following program running on a computer can
be stopped only through a hardware interrupt
mechanism and through no software intervention

int main()
{
int a = 0;
while (1)
{
a++;
a--;
}
return 1;
} ?
True 3Mark
False
Not Answer
12
Write a function to copy a file from a source to
destination starting from the 1st byte and then every
subsequent alternate Byte.(Assume the name of the
source and destination is specified through the
arguments . You may use only open , close , read ,
lseek,write calls for the file handling
operations .Write proper comments also) ?
4Mark
Page 5 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302

13
Write a program which creates 2 threads and these
two communicate with each other using an array of
integers of size 2. One thread(Writer) writes integers
into the array (one by one in individual array
elements), the other thread (Reader) continuously
reads from the array.

However access to the array should be synchronized
between the threads so that the first thread should
not write a new value in an array element before the
second thread has already read the old value from
that array element. It should be possible for Reader
and Writer to access different array elements
simultaneously however both of them should not be
accessing the same element together. Please use
POSIX compliant primitives in this program. ?

4Mark
14
Suppose you invoked the command ls -li in your
current directory and a portion of the output shows
three rows with the same number 4900520 as the
first column.What does it signify ? ?
The observation does not lead to any conclusion 3Mark
There are three copies of a file with inode number 4900520
There are three copies of a directory with inode number
4900520
Page 6 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302
The number 4900520 is the inode number of a file and the file
is having two links.
15
//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;
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);
Page 7 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302
}


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

4Mark
16
When a process opens a file , the file offset for the
position of the next I/O Operation is kept in ?
File Table 3Mark
Vnode Table
User File Descriptor Table
Inode Table
17
A computer that uses 32 - bit registers stores hex
value 1234 at address 0.The data stored in Little-
endian format at address locations 00 01 10 11 are ?
34 12 00 00 4Mark
00 12 34 00
00 00 12 34
12 34 00 00
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>
Page 8 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302
18
int main()
{
pid_t pid;
int childstatus;
pid = fork();
if (pid == 0) {
pid = fork();
if (pid == 0)
{
printf("child
");
}
}
else {
pid = wait(&childstatus);
}
return 1;
} ?
2 4Mark
4
0
1
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;
Page 9 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302




19
int exitstatus = 0;
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
");
} ?

4Mark
submit
Page 10 of 10
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=490&s2=20302

S-ar putea să vă placă și