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 ```