Ah, thanks for clarifying!
The purpose of these commands in this step is to set up a process that testuser will later terminate with their newly
defined sudo permissions.
Let's break it down:
-
pgrep top || echo "No top processes running": This command first checks if anytopprocesses are already running.pgrep top: Searches for processes named "top" and returns their PIDs if found.||: This is an "OR" operator. If thepgrep topcommand fails (meaning notopprocesses are found), then the
command after||will execute.echo "No top processes running": Simply prints this message if notopprocesses are found.
The primary goal here is to ensure we start fresh without existingtopprocesses, to avoid confusion.
-
sudo top &: This command starts thetopprocess (a real-time task manager) as therootuser and runs it in the
background.sudo top: Runstopwith superuser privileges.&: This symbol sends thetopprocess to the background, so your terminal prompt becomes available again
immediately, andtopcontinues to run without monopolizing your console.
Later in the step, testuser (with limited sudo access) will use the pkill command to stop this background top process,
thus demonstrating that our custom sudo rule works as intended.
Does that help clarify their purpose?