Bitpath

Lesson 1 · Unit 03

What is running

ps, top and PIDs, then exit status with $?, && and ||

12 exercisesabout 3 min

What you practise

  • ps aux, top, PIDs and parents, pgrep, exit status and $?, && and ||

Try a question from this lesson

Pick one

Your laptop fan is howling. ps aux lists every running program (some columns are trimmed here). Which one is to blame?

$ ps aux
USER  PID %CPU %MEM COMMAND
root    1  0.0  0.1 /sbin/init
ada   812  0.0  0.3 bash
ada   901 98.5  1.2 python train.py
ada   915  0.0  0.1 ps aux

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Processes and PIDs

A process is a running program. The kernel gives each one a number, its PID, and records which process started it: its parent, or PPID.

ps aux prints a snapshot of all of them. top shows the same list live, busiest first. pgrep name prints only the PIDs of processes with that name.

$ pgrep python
901
$ ps -o pid,ppid,cmd
  PID  PPID CMD
  812   790 bash
  901   812 python train.py

Concept

Chaining on success or failure

The shell can decide what to run next from an exit status.

a && b runs b only if a succeeded.

a || b runs b only if a failed.

a ; b runs b whatever happened.

shell
make build && ./deploy.sh
cd /data || echo "no /data here"

9 more exercises in the app

  • 2× multiple choice
  • 3× type the answer
  • 1× true or false
  • 1× fill the blanks
  • 1× match the pairs
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy