-
Notifications
You must be signed in to change notification settings - Fork 1
Processes and Users
The goal of the computing system is to run actions as instructed by the user. Instructions are run by the CPU (Central Processing Unit) in execution abstractions that we call processes. Processes are running programs, i.e. executable code that now uses system resources. Processes hide CPU, memory and complexity from the user. It is the role of the operating system to ensure fair access for all processes to system resources.
In this chapter we delve into key concepts related to processes and process scheduling. We present the POSIX API for working with processes. We look into shell internals: running commands, redirections, pipes, subshells.
You will get accustomed to the POSIX process API: creating, waiting and terminating processes. As a critical component of the operating system, you will be understand the importance of monitoring and fine-tuning process resource use (CPU, memory, I/O). The shell is arguably the most used process in the operating system; you will get a better grasp of the shell inner workings.
- running actions, run instructions on CPU, multiple instructions
- separation, processes
- CPU, memory, I/O abstractions
- scheduling processes, priorities, I/O-bound vs CPU-bound
- creating and terminating processes
- process investigation
- shell processes, subshells, foreground, background
- redirection
Process runs and uses CPU, memory, I/O. Show CPU time/percentage, virtual memory and resident memory for process. Use shell as test case.
Run processes with nice priority altered, see time duration. Difference between user time, system time, wall time. 04-processes/nice
Show redirection using dup()
and dup2()
. 04-processes/redirect
.
Show the use of fork()
to create new process. Show use of fork()
+ exec()
. 04-processes/fork-exec
Show different executors: 04-processes/executor
Show adoption of orphan child processes. 04-processes/orphan
.
Inspect shell using strace
when using internal commands vs external commands. Inspect running in background. Use shell and strace -p <shell_pid>
.
Show example with pipe()
. Inspect with lsof
. 04-processes/pipe
.
Inspect process with an environment variable set. 04-processes/environ
. Run using:
$ ./environ-with-fork
$ AUTHOR=thanos ./environ-with-fork
Show what happens when we use echo "a" | read v, vs read v <<<"a".
Redirecting output of two chained commands. (a ; b) > f
Inspect tee
using strace
. Inspect tee -a
.
What does the daemon()
call do? Create a program that calls daemon()
then call sleep(100)
then inspect it.
Start process as root
and create child process as another user using setuid()
. Run setuid()
after forking. Exec a new process and use getuid()
.
Programmatically get resource usage for process through getrusage()
.
Start process using posix_spawn
.
Implement a program that reads data from standard input and sent it back to standard output using ANSI C calls. Use popen
to create a process from previous program, send data to it and read data from it.
Update 04-processes/pipe
to use exec to do cat /etc/passwd | grep 10
.