Abstraction: Process and Process API


Program and process

What is a program?
What is a process?

Process API

The operating system provides an API to help managing processes. Minimally, the followings are provided:


Process creation

When a program is run, the OS performs the following steps:


Loading: from program to process


Process: data structure


Process API

Include three function calls:

Hands-on: setup
1
2
cd ~/ostep-code/cpu-api
make
fork()
Hands-on: fork()
View source code of p1.c on Code browser

~~~bash ./p1

What do you notice?
Processes management using wait()
Hands-on: wait()
View source code of p2.c on Code browser

~~~bash ./p2

What do you notice?
exec()
Hands-on: exec()
View source code of p3.c on Code browser
1
./p3
Why fork(), wait(), and exec()?

The Shell

What is the UNIX shell?

In Unix, the shell is a program that interprets commands and acts as an intermediary between the user and the inner workings of the operating system. Providing a command-line interface (that is, the shell prompt or command prompt), the shell is analogous to DOS and serves a purpose similar to graphical interfaces like Windows, Mac, and the X Window System.

Hands-on: redirection
1
2
3
wc p3.c
wc p3.c > newfile.txt
cat newfile.txt
Hands-on: redirection and file descriptors
1
2
3
4
./p4
ls
cat p4.output
cat -n p4.c

Other system calls …