-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsample_exams.html
132 lines (109 loc) · 3.42 KB
/
sample_exams.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<head>
<title>Unix programming in C - sample exam tasks</title>
<script type='text/javascript'>
function write_last_mod ()
{
var loc = new String (document.location);
if (loc.match (/\.html($|\?.*)|\/$/)) {
var last_modified = new Date (document.lastModified);
// var date_stamp = last_modified.toDateString ();
// document.writeln (date_stamp);
document.writeln (last_modified);
}
}
</script>
</head>
<body bgcolor="#ffffff">
<h1>Sample exam tasks</h1>
<h2>TCP server and client with signal handling (medium difficulty)</h2>
<p>
Produce 2 programs, client and server. They will be passing data over TCP
socket. They will be running on the same system.
The client will accept command line argument saying signal number
and optionally a port and connects to the server (use localhost implicitly).
It will send its PID and signal number.
</p>
<p>
Server will send said signal to the PID, write a message to stdout.
The client has to handle the signal, write a message to stdout and exits.
Server is single threader, after reading the data and sending singal
it will enter sleep again via <tt>accept()</tt>.
</p>
<p>Variant: use UDP</p>
<h2>Thread pool (easy)</h2>
<p>
Main thread will create number of threads as specified on command line.
Each thread simulates some work via <tt>sleep()</tt> for random time,
1 to 10 seconds. After that it signals to the main thread it is about to exit.
Main thread will immediately create new thread.
</p>
<p>
The goal is to keep around the same number of threads. Each thread
has its own number that will be written to stdout after the thread starts
running and before its exit.
</p>
<p>
Use mutexes for synchronization and condition variables for signalling.
</p>
<h2>Shell command simulation (medium difficulty)</h2>
<p>
Copy <tt>/etc/services</tt> to current working directory using
<tt>open</tt>, <tt>read</tt>, <tt>write</tt>, <tt>close</tt>.
Then simulate command
<tt>cat services | grep tcp | wc -l</tt>.
</p>
<p>
This has to be done so that each of the 3 commands is done using its
own exec from its own process.
Connect the processes with pipes and wait in the main process for the
other processes to finish.
Main process does not use exec and therefore it is necessary to call
<tt>fork</tt> 3 times. Command <tt>wc</tt> does not have to pass the data
to the main process, it is sufficient to write them out to the terminal.
</p>
<h2>inetd (difficult)</h2>
<p>
Write simple inetd server for TCP services. Configuration is stored
in text file that looks like this:
</p>
<pre>
2222
/bin/cat
3331
/bin/sed
3332
...
...
...
</pre>
<p>
Server listens on all ports. Uses <tt>select</tt> or <tt>poll</tt>.
New connections leads to new process, its file descriptors 0, 1 and 2
are redirected to the new process and calls <tt>exec()</tt> for given
program. These processes are then running independently.
</p>
<p>
For simplicity you can assume that the programs do not have other
parameters.
After each accept deal with zombies, if any.
</p>
<p>
The processing of the configuration file has to be done using
<tt>open</tt>, <tt>read</tt>, <tt>close</tt>.
<p>
To check the functionality use Netcat. In case of
<tt>/bin/cat</tt> it is sufficient to connect to given port
and send some characters - they should be echoed back unchanged.
</p>
<pre>
$ nc localhost 2222
foo
foo
</pre>
<p><hr>
Last change:
<script>
write_last_mod ();
</script>
</body>
</html>