Systems Programming Midterm Fall 2017 Answers
Systems Programming Midterm Fall 2017 Answers
SOFE 3200U
Systems Programming
Fall 2017
Midterm Exam
Time: 70 minutes
Name: __________________
Part A /6
Part B /10
Part C /4
a- /home
b- /home/sofe3200
c- /users
d- /users/sofe3200
Answer: __b___
a- ls
b- pwd
c- dir
d- None of the above
Answer: ___b__
3- In bourne again shell (bash) if a variable does not exist before assigning a value to it, the
shell will
Answer: __b_
a- set a = 2 * 2
b- @a = 2 * 2
c- a=2*2
d- None of the above
Answer: __b__
5- printf () library function always sends its output using file descriptor
a- 0
b- 1
c- 2
d- 3
Answer: _1___
a) socket
b) pipe
c) signal
d) none of the above
Answer: __a__
a) 0 to 127
b) 0 to 255
c) 1 to 128
d) 1 to 256
Answer: __b___
8- A parent process may wait for one of its children to terminate and then accept its child's
termination code by executing
a) sleep()
b) kill()
c) delay()
d) None of the above
Answer: __d___
• Application programs must talk to the operating system for services like -
• file creation,
• process duplication
• interprocess communication
• They can do this via a collection of routines called system calls.
Example: open(), close(), read(), write(), fork() etc.
Answer:
If a process's parent is alive but never executes a wait(), the process's return code will never be
accepted and the process will remain a zombie.
Answer:
Perl functions are simple to use, although the syntax can get complicated. A simple example of a
Perl function will give you the idea:
To call the function, your Perl script would look like this:
Answer:
for executing commands one by one ;
for executing commands in the background &
6- What are the differences between absolute path and relative path in Linux? Shown an
example.
Answer:
7- What are different file permission specifications for the chmod command?
Answer:
8- What is the typical sequence of events associated when a child process reads the message
buffer of the parent using unnamed pipes?
Answer:
The typical sequence of events is as follows:
1. The parent process creates an unnamed pipe using pipe ().
2. The parent process forks.
3. The writer closes its read end of the pipe, and the designated reader closes its write end
of the pipe.
4. The processes communicate by using write () and read () calls.
5. Each process closes its active pipe descriptor when finished with it.
Answer:
#include <stdio.h>
#include <signal.h>
main ()
{
void (*oldHandler) (); /* To hold old handler value */
printf ("I can be Control-C'ed\n");
sleep (3);
oldHandler = signal (SIGINT, SIG_IGN); /* Ignore Control-C */
printf ("I'm protected from Control-C now\n");
sleep (3);
signal (SIGINT, oldHandler); /* Restore old handler */
printf ("I can be Control-C'ed again\n");
sleep (3);
printf ("Bye!\n");
}
Or
#include <stdio.h>
#include <signal.h>
main ()
{
void myhandler();
void (*oldHandler) (); /* To hold old handler value */
printf ("I can be Control-C'ed\n");
sleep (3);
oldHandler = signal (SIGINT, myhandler); /* Ignore Control-C */
printf ("I'm protected from Control-C now\n");
sleep (3);
signal (SIGINT, oldHandler); /* Restore old handler */
printf ("I can be Control-C'ed again\n");
sleep (3);
printf ("Bye!\n");
}
void myhandler(){
printf(“Do nothing”);
}
The new Maclean’s survey puts the university in the top 10 of Canada’s 19 primarily
undergraduate universities. Based on specific methodology, the university has risen in the
overall rankings from No. 15 in 2012 to No. 8 this year.”
Write a shell script to display the number of occurrences of the word “the” in “news.txt”.
Answer: