Sie sind auf Seite 1von 13

THE TEST ON CS

TimeLeft=1:29:53
1
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 ?
open() followed by fork() 3Mark
fork() followed by exec()
read() followed by fork()
fork()
2
Please look at the following code and select the
correct option

//file.c

int globalobj;

int main

{

char * pobj;

int lobj;

pobj = malloc(10);

} ?
pobj & lobj would go into stack area 4Mark
Page 1 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
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
3
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 login shell decreases. 3Mark
The priority of your running process decreases.
The priority of your running process increases.
None of them is a correct observation.
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 4Mark
Page 2 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
0
1
2
5
What will be the output of the program when I run
the executable created from it, and how many new
processes will be created by this program when it is
executed? There is one particular thing about this
piece of code, can you point 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;
} ?

4Mark
6
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
Page 3 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
the signal handler for SIGINT in the execed
program. ?
Yes 3Mark
No
None of the above
all of the above
7
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? ?

8Mark
8
What happens when a parent process terminates
before the termination of a child process in Unix
Page 4 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
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
9
What happens when a process having no child
process executes a wait call ?
Returns with the termination status of a zombie child. 3Mark
Runtime error may occur .
Blocks the process
Returns immediately with an error
10
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
11
Which data structure(s) is used by the UNIX kernel
to manage files opened by a process? ?
Inode table 3Mark
Use File Descriptor Table
File Table
All of these
Page 5 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
12
//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));
}
//Code ends here ?

4Mark
13
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.
Page 6 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
This is to be done in Unix and not OES. ?

4Mark
14
What is the unix command to print the processor
type of the machine ?
none of the others 3Mark
environ
uname
architecture
15
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
Page 7 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302

16 A 64 bit processor means ?
There are 64 registers 3Mark
None of these
It can support 64 MB of main memory (max)
It can support 64 I/O devices
//Two implementations are to achieve same
functionality. Provide comments on this.


//Common code
int gvar = 0;
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);
Page 8 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
17
}


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


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


//Implementation 2

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

5Mark
18
Write a shell program which can start a new process
on receiving a command from the user and run that
command in this new process. The shell should be
able to to redirect standard output of the new
program to a file (i.e., take care of the following
scenario): $a.out > tempfile ?

5Mark
19
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
Both are true
1 is true and 2 is false
20
A machine that uses 32-bit register stores the hex
value 1234 at address 0.the data stored on big-endian
form on respective locations 00,01,10,11 are ?
12 34 00 00 4Mark
34 12 00 00
Page 10 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
00 00 34 12
00 00 12 34
21
//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
} ?

5Mark
Page 11 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302
22
What is the unix command to print the nodename
(the name by which a system is known to a
communication network. ?
uname -n 3Mark
su
none of these
netstat -rn
23
What will be the output if I run the program q7 as
follows: $./q7


//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) {
Page 12 of 13
2/6/2009 http://10.203.161.13/OES/take.jsp?s1=509&s2=20302




printf("child process ");
}
else {
pid = wait(&exitstatus);
printf("parent process ");
}
return 1;
} ?

5Mark
24
Explain how would a Loader work on a system
which supports virtual memory & virtual addresses
in programs to be loaded in main memory for
execution vis-a-vis on a system which does not
support virtual memory/address? (Loader is a
program which loads an executable in main memory
from disk for execution) ?

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

Das könnte Ihnen auch gefallen