You are on page 1of 8

THE TEST ON CS

TimeLeft=0:49:48
1
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
None
Malloc needs to access at least one static variable.
No function should be called within the code of malloc.
2 A 64 bit processor means ?
None of these 3Mark
It can support 64 MB of main memory (max)
There are 64 registers
It can support 64 I/O devices
3
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 ?
00 12 34 00 4Mark
12 34 00 00
00 00 12 34
34 12 00 00
4
What is the unix command to print the nodename
(the name by which a system is known to a
communication network. ?
Page 1 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=494&s2=20302
netstat -rn 3Mark
none of these
su
uname -n
5
Write a program that creates two timers. One of
them expires after every 2 seconds and the other one
expires after every 1.5 seconds. On expiry of each of
the timers the program calls two different functions.
These different functions print the message "timer
expired" along with the timer id. ?

4Mark
//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);
}
Page 2 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=494&s2=20302
6


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()
} ?

4Mark
//There are two different main functions (alternative
defns). Which of them will use cache effectively, if
the cache size is small? Justify your reason.

//1st Alternative
int main()
{
int i = 0;
Page 3 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=494&s2=20302
7
while (i++ < 100)
thred1();
while (i++ < 200)
thred2();
}

//2nd Alternative
int main()
{
int i = 0;
while (i++ < 100)
{
thred1();
thred2();
}
}

//Common Code
int gvar = 0;
void thred1() {
int i = 0;
while (i++ < 200)
{
gvar++;
}
}


void thred2() {
int i = 0;
while (i++ < 100)
{
gvar--;
}
Page 4 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=494&s2=20302
} ?

4Mark
8
//The following code prints an address of a variable.
What type of address is this? virtual, physical or
cache address etc.? Justify your answer in short.

int main()
{
int i = 0;
printf("address of i : %u ", &i);
return 1;
} ?

4Mark
9
You have executed the following function call in our
code nice(-10).What is the correct observation based
on this function call.(non super user) ?
The priority of your running process increases. 3Mark
None of them is a correct observation.
The priority of your login shell decreases.
The priority of your running process decreases.
10
Write a program in which the main function calls a
function, say yourfunc(), 1000 times in a loop. The
function yourfunc() executes a for loop for 10,000
times to increment a global variable by 1 in each
iteration.Print the final value of the variable in your
Page 5 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=494&s2=20302
main function.Use suitable functions in your code to
display an estimate of the total execution
time of the loop calling yourfunc() in main. This to
be done in Unix system and not in OES. ?

4Mark
11
All types of signals can be caught and handled by a
program by calling "signal()" system call. ?
True 3Mark
False
Not Answer
12
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
Page 6 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=494&s2=20302

13
Suppose two threads are created thread1 and
thread2.Thread1 executes the function do_work_one
() and thread2 executes the function do_work_two
().What is the possible output for the following code:
do_work_one()
{
pthread_mutex_lock(&first_mutex);
pthread_mutex_lock(&second_mutex);
sleep(20);
pthread_mutex_unlock(&second_mutex);
pthread_mutex_unlock(&first_mutex);
pthread_exit(0);
}
do_work_two()
{
pthread_mutex_lock(&second_mutex);
pthread_mutex_lock(&first_mutex);
sleep(20);
pthread_mutex_unlock(&first_mutex);
pthread_mutex_unlock(&second_mutex);
pthread_exit(0);
} ?

4Mark
Create a memory management library which
provides 2 routines one for dynamically allocating
Page 7 of 8
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=494&s2=20302




14
memory and another one for freeing the allocated
memory) .Use linked-list based approach. Don't use
brk/sbrk system calls.
?

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