Skip to content

Linux Foundations / Manage a Linux host ยท Step 24 of 50

Lesson: What a process is made ofSwitch
โ† Linux Foundations

System administration

What a process is made of

See the identity, state and resources the kernel records for each process.

A program is a file on disk. A process is that program in motion. Run the same program twice and you get two processes, each with its own memory and its own records in the kernel.

What the kernel tracks

For every process the kernel keeps, among other things:

  • a process ID (PID) and a parent process ID (PPID)
  • the user and group it runs as
  • its state, such as running or sleeping
  • its memory, open files and current working directory
  • its priority and the CPU time it has used

The shell variable $$ holds the shell's own PID, so you can inspect it:

bash
$ echo $$
2145
$ ps -o pid,ppid,user,stat,comm -p $$
    PID    PPID USER     STAT COMMAND
   2145    2144 maria    Ss   bash

Memory is private

Each process gets its own virtual address space. One process cannot simply read or overwrite another's memory, so a bug in your editor does not corrupt your web server. Processes that want to exchange data use channels the kernel provides, such as pipes, sockets or shared memory they set up on purpose.

Open files

A process refers to its open files by small numbers called file descriptors. By convention 0 is standard input, 1 is standard output and 2 is standard error.

bash
$ ls -l /proc/$$/fd
lrwx------ 1 maria maria 64 Jun  3 10:00 0 -> /dev/pts/0
lrwx------ 1 maria maria 64 Jun  3 10:00 1 -> /dev/pts/0
lrwx------ 1 maria maria 64 Jun  3 10:00 2 -> /dev/pts/0

You may see extra entries. They are other files the shell has open.

Identity decides permissions

A process acts with the rights of the user it runs as. If you start cat, it can read only what you can read. Children normally inherit the user, environment variables and working directory of their parent.

Each process has its own working directory. That is why cd has to be built into the shell. A separate cd program could only change its own directory and then exit.

bash
$ readlink /proc/$$/cwd
/home/maria

Try it

Start sleep 300 &, note the PID it prints, then run ps -o pid,ppid,user,stat,comm -p PID with that number. Check that the PPID matches echo $$. Then look in /proc/PID/. The processes and cron lab is a good place to try this.

Check your understanding

What a process is made of

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.