summaryrefslogtreecommitdiff
path: root/EXAM.md
blob: 2e39bfaca9b8b109220b0685668421933f2c5eb6 (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
The final is a 2-hour closed-book online exam.
You need to answer short-answer questions and simple shell programming questions,
covering almost all the topics you are supposed to have studied throughout the course.

Here are some sample questions:

1. Identify kernel function and components.
1. Identify the importance of programming Unix in C.
1. Define inter-process communication (IPC).
1. Write a shell script that searches the password file for an input name and sends that person a "hello" message.

I hope the above information will be enough for you to prepare for the final exam.

Best wishes!

===============================================================================

# Identify kernel function and components

> The Linux kernel consists of several important parts: process management, memory
> management, hardware device drivers, filesystem drivers, network management, and
> various other bits and pieces. - https://www.tldp.org/LDP/sag/html/kernel-parts.html

* process management
* memory management
* hardward device drivers
* filesystem drivers
* network management


```text
                                  -----------------------
                                  | User space programs |
                                  -----------------------
                                            |
                                            V
-----------------------------------------------------------------------------------------------
                                          Kernel
                        -----------------------------------------------
                                  System call interface
                        -----------------------------------------------

____________________   ___________________
|Virtual file system|  | Memory manager  |  | Process manager |  | Network services (sockets) |
--------------------   -------------------

| filesystem driver |                                            | tcp/ip drivers |

                                                                 | ethernet card driver |

-----------------------------------------------------------------------------------------------
                                        Hardware
-----------------------------------------------------------------------------------------------
```

## Services

* init: first process started. performs startup chores.
  * single user mode
  * multi user mode aka run levels
    * 0: system halt
    * 1: single user mode
    * 3: multi user mode
    * 5: start gui
    * 6: system reboot
  * starts `getty`
  * init -> getty -> login -> shell
* syslog: aggregates logs
* cron: runs program regularly on a schedule
* at: runs program at a specific time once.
* GUI:
  * X Window system: X
  * Window managers: fvwm, icewm, blackbox, windowmaker
  * Desktop manager: KDE, Gnome
* Networking:
  * telnet
  * ssh
  * rlogin
* Network file systems
  * NFS supported by kernel
  * CIFS supported through Samba
* Mail
  * Mail Transfer Agent (MTA): delivers email to local or remote mailbox. e.g sendmail, postfix
  * Mail User Agent (MUA): used to read mail. e.g. pine, evolution
  * usually stored in /var/spool/mail
* Printing
  * print queue: manages which job to print.
  * print queue software spools the printouts on disk.
* File system
  * /bin
  * /lib
  * /etc
  * /dev
  * /usr: unchanging data.
  * /var: changing data like logs

# Identify the importance of programming Unix in C

The C programming language was developed in the 1970's around the same time that
the original UNIX was being built and designed. C provides low level constructs
that allow programmers to decide how to allocate and deallocate memory. This
level of efficiency is necessary for building the Kernel that most software
programs depend on. The system call interface is exposed through man pages and
header files. libc is the standard interface for making system calls into the
kernel.

# Define inter-process communication (IPC)

> IPC refers specifically to the mechanisms an operating system provides to
> allow the processes to manage shared data. - https://en.wikipedia.org/wiki/Inter-process_communication

Operating systems provide IPC mechanisms to allow processes to communicate state
with one another. This can be for many different reasons including taking a lock
on a resource, streaming data from one process to another or synchronizing
changes from one process to another.

Some examples of IPC mechanisms are:

* file: A file can be used as a lock to ensure that only one process performs
  a restricted action at a time. `man flock`
* signal: using the `kill` program one program can send a signal to another
  program for various reasons such as reloading configuration or performing a
  graceful shutdown.
* socket: A TCP/UDP can be used for streaming data across a network.
* UNIX domain socket: Can be used to stream data from one process to another on a host.
* Pipes: A program can write to stdout which can be piped into stdin of another process.


# Write a shell script that searches the password file for an input name and sends that person a "hello" message.

`/etc/passwd` format.

| login | password set | uid | gid | comment | home dir | shell |


```sh
#!/bin/sh

cd "$(dirname "$0")/.."
USER=${1}

# broadcast
for i in `grep $USER /etc/passwd | cut -d: -f1`; do
  (echo 'hello' | write "$i") || true
done

# or find a specific user
if cat /etc/passwd | cut -d: -f1 | grep -E "^$USER"; then
  echo "hello" | write "$USER"
else
  echo "I could not find '${USER}'"
  exit 1
fi
```