>_ IzzyLab

Hands-on task

This task is step 4 of the course “Processes and signals”

/proc: a process's command line

medium~5 min

report-worker is running on the system, and nobody remembers which arguments it was started with. Read its command line from /proc/PID/cmdline and write it to /root/cmd.txt with each element on its own line — exactly as the kernel sees them, starting with the program itself. Note: one of the arguments contains a space.

What you'll practise:
  • /proc
  • cmdline
  • processes
  • tr
  • null byte

Topic breakdown

The virtual filesystem /proc is the kernel's window into the system's state: a /proc/PID/ directory is created for each process, and inside it are pseudo-files with its metadata. The cmdline file holds the command-line arguments exactly as the process received them: as an array of C strings separated by a null byte (\0), not spaces — so a naive cat mashes everything into a mess. To get a readable string, the null bytes must be replaced with spaces by a character-by-character stream translator (see tr), and the PID found by the process name (pgrep).

What's checked

  1. report-worker is running
  2. report-worker's command line is split into lines

What it looks like