Courses/Computer Science/CPSC 457.F2014/Lecture Notes/Creation
Process Creation
In this session, we consider a definition of the term 'process' and what a process's main properties and characteristics are. We will observe how processes are created and destroyed; we will do these activities from the perspective of the system call layer.
We will also touch on the topic of OS--level concurrency via fork(2), vfork(2), and clone(2). This forecasts later topics like IPC (interprocess communication). In fact, the way Linux represents a process and a thread are exactly the same, and Linux uses the term "lightweight process" to represent this idea: a thread is a process and a process is a thread. The only real difference is that a group of threads may share access to the same process address space (i.e., set of memory regions).
Up until this point, we have been working with an intuitive notion of what processes are: they are a running software application. Userland processes are "programs in execution." We have seen a few tools for observing the set of running programs and their properties, e.g., top(1), ps(1). We've seen how to interact with and control them through command line utilities like kill(1).
In this session, we will continue building our understanding of the process abstraction as a virtual CPU context (i.e., a snapshot of the execution state of a program) and a processes other properties. We will focus on an examination of how processes come to exist. We will start by considering what a process is (see task_struct for how Linux maintains metadata about a process).
We will also have a multi-perspective look at the routines
- fork(2) / clone(2) / vfork(2)
- execve(2)
Notes
We started with a brief discussion of current events (ShellShock):
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
Which leads to a nice discussion of the ASCII fork bomb: http://jaromil.dyne.org/journal/forkbomb_art.html
:(){:|:&};:
and process creation via fork(2).
What is involved in process creation? How does a process actually come to exist? We will glance over the source code of the kernel's routines for creating (or cloning) a process and loading an executable (i.e., ELF) image into a process address space. They lead to a chain of procedures in the OS that is a bit deeper and more complex than the system call interface might otherwise imply.
- recall: what is the purpose of an OS?
- to support the loading and execution of programs
- protection / isolation between processes
- multiplex resources for processes (provide the illusion of concurrent access and clean sharing)
- what is a process?
- a process is a program in execution
- in some sense, it is a virtual CPU
- PCB task_struct
- PAS (we will consider the structure of this next session)
- what parts of the syscall API can be used to create a process?
- the do_fork routine
- the copy_process routine
- connecting the ELF ABI with process creation / loading load_elf_binary routine, via execve()
- exit() syscall entry point: http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/kernel/exit.c#L1037
- do_exit() service routine: http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/kernel/exit.c#L888
- sys_clone function signature: http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/include/asm-generic/syscalls.h#L12
- sys_clone IA-32 prototype: http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/arch/x86/include/asm/syscalls.h#L41
- sys_clone implementation http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/arch/x86/kernel/process_32.c#L433 calls
- ptrace entry point: http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/kernel/ptrace.c#L602
- sys_execve http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/arch/x86/kernel/process_32.c#L451 calls:
We'll deal with an in-depth examination of the process address space next session
Code
http://www.cpsc.ucalgary.ca/~locasto/teaching/2014/CPSC457/code/spawn.c
Scribe Notes
Readings
- LDK Chapter 3
- MOS: Section 2.1: Processes (this should be partly review of what we've talked about in class)
- MOS: Section 10.2.5 (Linux kernel structure)
- MOS: Section 10.3.1 (about processes in Linux) should reinforce some class discussion