Sie sind auf Seite 1von 14

THE TEST ON CS

TimeLeft=0:59:54
1
Create two programs Client and Server. They
communicate using two FIFOs. The client sends a
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. ?

4Mark
Please look at the following code and select the
correct option

//file.c

int globalobj;
Page 1 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
2

int main

{

char * pobj;

int lobj;

pobj = malloc(10);

} ?
lobj will go into stack and pobj would go into heap 4Mark
none of the options are true
lobj will be on stack and the object pointed to by pobj would
go into heap
pobj & lobj would go into stack area
3
Write a program which creates a pipe and after that
creates a child process. Parent Process sends the
process id of itself to the child process on the pipe.
Child Process receives the process id of the parent
and uses the received process id of the parent to send
a signal SIGINT to the Parent Process and the
Parent Process on receiving the signal prints the
message "Interrupt handled" and exits.
This is to be done in Unix and not OES. ?

4Mark
4
A computer that uses 32 - bit registers stores hex
value 1234 at address 0.The data stored in Little-
Page 2 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
endian format at address locations 00 01 10 11 are ?
00 12 34 00 4Mark
34 12 00 00
00 00 12 34
12 34 00 00
5
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 ?
1 id false and 2 is true 5Mark
Both are false
1 is true and 2 is false
Both are true
6
During context switch, CPU does not do any useful
work as far as program execution is concerned ?
True 3Mark
False
Not Answer
7
In Unix The "dup" function returns the "lowest
numbered free entry in the user file descriptor table
". ?
True 3Mark
False
Not Answer
In Unix environment, if you want to start running a
Page 3 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
8
different new program in a new process(i.e.,
program x from program y), which system calls
would you use ?
fork() followed by exec() 3Mark
read() followed by fork()
fork()
open() followed by fork()
9
Choose the function, which a process uses to
synchronize its execution
with the termination of its child ?
lstat() 3Mark
exit()
wait()
signal()
10
What is the output of the following program code:
main()
{
fork(); fork(); fork();
printf("Hello World");
} ?
Hello world will be printed 1times. 4Mark
Hello world will be printed 3 times.
Hello world will be printed 27 times.
Hello world will be printed 8 times.
//Two implementations are to achieve same
functionality. Provide comments on this.


//Common code
int gvar = 0;
Page 4 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
11
mutex gmx;

int main()
{
create thread 1 with start routine strthr1()
create thread 2 with start routine strthr2()
}



//Implementation 1

void cfn(int i)
{
mutex_lock(&gmx);
gvar=i;
mutex_unlock(&gmx);
}


void * strthr1(void * thr_p)
{
cfn(0);
}


void * strthr2(void * thr_p)
{
cfn(8192);
}


//Implementation 2

Page 5 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
void cfn(int i)
{
gvar=i;
}


void * strthr1(void * thr_p)
{
mutex_lock(&gmx);
cfn(0);
mutex_unlock(&gmx);
}

void * strthr2(void * thr_p)
{
cfn(8192);
} ?

5Mark
12
The function commonly used to return a structure of
information about a named
file is : ?
s_isreg() 3Mark
stat()
chown()
s_isdir()
13
readdir() is a system call, which can be used to read
a directory file ?
True 3Mark
False
Page 6 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
Not Answer
14
"Open()" system call can be used to open a file as
well as create a file. ?
True 3Mark
False
Not Answer
15
Write a program which creates 2 threads and the
threads communicate with each other using a global
variable. One thread writes continuously(in a loop)
into the global variable and the other thread
continually reads from the global variable. However
access to the global variable should be synchronized
between the threads such that the first thread should
not write a new value in the global variable before
the second thread has read the previously written
value. (This is called a Producer-Consumer
problem). Please use only POSIX compliant
primitives in this program. ?

4Mark
What will be the output of the following program?
How many new processes will be created by this
program?

int main()
{
pid_t pid;
int childstatus;
pid = fork();
Page 7 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
16
if (pid == 0) {
fork();
fork();
printf("child
");
}
else {
pid = wait(&childstatus);
printf("process id of child %d", pid);
}
return 1;
} ?

4Mark
17
What happens when a parent process terminates
before the termination of a child process in Unix
Operating System ?
The parent process id of the child is changed to 1 3Mark
Swapper becomes the parent of the running child
The child process is marked as zombie.
The parent process id of the child is changed to 0
18
"close()" system call is used to delete a file from the
file system ?
True 3Mark
False
Not Answer
19
signal() system call is used to attach a signal handler
function to a signal ?
True 3Mark
Page 8 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
False
Not Answer
20
Please look at the following structure of the directory
("/user/gur55555") and select the correct statements

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 4
entries {{"src", indode_1}, {"obj", indode_2}, {"bin",
indode_3}, {"makefile", indode_4}, }
3Mark
directory file "/user/gur55555" will contain a table having 11
entries for all regular files and subdirectories (their names and
inode numbers)
directory file "/user/gur55555" will contain a table having 1
entry {{"makefile", indode_1}}
directory file "/user/gur55555" will contain a table having 3
entries {{"src", indode_1}, {"obj", indode_2}, {"bin",
indode_3}}
21
Write a program to copy certain contents of a file to
another file. The program should start by copying
the 1st byte of the source file to the destination file
and then every subsequent 10th Byte should be
copied. The name of the source and destination files
are specified through the command line arguments.
You may use open, close, read, lseek, write system
calls for the file handling operations. Write proper
comments also. The program is to be done on Unix. ?
4Mark
Page 9 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302

22
The address space of a running program is typically
divided into following areas: Text, data, heap and
stack. Can you please explain what do you keep
where with examples from the following program?
Every object must be discussed.

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

7Mark
23
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 'c' is 0x10000020, Address of object 'b' is
0x10000010, Address of object 'a' is 0x10000000
4Mark
Address of object 'a' is 0x10000000, Address of object 'c' is
0x10000010, Address of object 'b' is 0x10000020
Address of object 'c' is 0x10000000, Address of object 'a' is
0x10000010, Address of object 'b' is 0x10000020
Address of object 'a' is 0x10000020, Address of object 'b' is
0x10000020, Address of object 'c' is 0x10000020
Page 11 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
24
Write 2 dynamic memory management routines (one
for allocating memory and another one for freeing
the allocated memory) providing the functionality
and interfaces similar to malloc() and free()
functions provided by the standard C library. Write
both these functions in a file named as -
memorymgmt.c. The functions should be thread-
safe, i.e., can be called from multiple threads
simultaneously without any issues.

Write a few more functions in another file -
program.c, the main() function defined in program.c
should create at least 2 threads. These threads
should use mymalloc() and myfree() functions
defined in memorymgmt.c file to allocate/deallocate
memory dynamically. User Posix compliant calls for
threads.

To be done in Unix and not in OES. ?

4Mark
25
Before getting data or instruction from a main
memory location, the CPU always makes the
Program Counter Register to refer to that location. ?
True 3Mark
False
Not Answer
26 On-Chip Cache has ?
become obsolete 3Mark
Page 12 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302
lower access time than RAM
larger capacity than off chip cache
its own data bus
27
Write a program to check the endianness of your
machine.(The endiannes should be discovered by the
program itself without any input from the user.
Program should print "little-endian machine" if it
finds a little endian machine else should print "big-
endian machine" if it discovers a big-endian
machine). This code is not to be written in OES. It
should be written on Unix. ?

4Mark
28 A parity bit is ?
used to detect errors 3Mark
is the first bit in a byte
is the last bit in a byte
used to indicate uppercase letters
29
A process has an address space which it can't
transgress (jump out of) without making a system
call ?
True 3Mark
False
Not Answer
30
Which program segment at run time is used to store
interrupt and subroutine(funtion) return addresses ?
Data Segment 3Mark
Extra segment
Page 13 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302




Code Segment
Stack Segment
31
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;
} ?
0 4Mark
4
1
2
submit
Page 14 of 14
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=508&s2=20302

Das könnte Ihnen auch gefallen