-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
96 lines (75 loc) · 4.18 KB
/
README
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
____ ___ ____ _
| _ \ _ __ ___ ___ ___ ___ ___ ___ ___ ( _ ) | _ \(_)_ __ ___ ___
| |_) | '__/ _ \ / __/ _ \/ __/ __|/ _ \/ __|/ _ \/\ |_) | | '_ \ / _ \/ __|
| __/| | | (_) | (_| __/\__ \__ \ __/\__ \ (_> < __/| | |_) | __/\__ \
|_| |_| \___/ \___\___||___/___/\___||___/\___/\/_| |_| .__/ \___||___/
|_|
Description
-----------
When you start a program through a command in the shell, or other interaction
with the operating system, the system will spawn a new process for that
program. But this is not the only way that new processes are created, it is
also possible to create processes programmatically.
This programming exercise is about creating two processes programmatically, and
connecting the created processes with a unidirectional communication channel, a
pipe.
The semantics of process creation are different between different families of
operating systems. In POSIX compliant systems, there is the fork system call,
which duplicates the currently executing process and all its resources. On the
other hand, the CreateProcess Function on Windows creates a new process from a
blank slate, without duplicating the current process.
Because of this difference in semantics, the programming interface is used very
differently as well. The difference is outlined in the sketch below:
POSIX semantics: | Windows semantics:
|
... | ...
| | |
v | v
fork() * ---- x | CreateProcess() * o
| | | | |
pid != 0 | | pid == 0 | | |
v v | v |
wait() * * exec(...) | WaitForSingleObject() * |
--- | | --- |
... | ...
| | |
v | v
* exit() | * exit()
--- --- | --- ---
| | |
v | v
... | ...
|
Exercise Questions
------------------
Choose whether to do this exercise on Windows or a UNIX-like system. Depending
on your choice of System, use the following functions to implement process
creation:
Windows: CreateProcess
POSIX: fork, exec*
The code already implements the comprehension of the command line arguments,
and provides your code with two arrays representing a first and a second
command. The first element of these arrays is the program to start, and all
further arguments are the arguments that are to be passed to the program as
parameters. Remember that on UNIX, the first argument to the program executing
through exec is the name of the program itself. Refer to `man 3 exec` for
details.
When you are able to successfully start the two processes, begin to connect
them through a pipe, such that the output of the first command becomes the
input of the second command. Use the following functions to implement the pipe:
Windows: CreatePipe
POSIX: pipe, dup*
Content
-------
This repository contains the following source code files:
processes_pipes.c
~~~~~~~~~~~~~~~~~
This file contains the main function, as well as several utilitiy functions for
input and output, which are explained with inline comments. Extend the main
function with your code for process creation and creation of the pipe.
Credits
-------
This repository was created by the Operating Systems and Middleware Group at
Hasso Plattner Institute, University of Potsdam, to help teach operating system
behaviour and internals.
For feedback and more information, contact bs@hpi.de