Introduction
A security command can keep running after its useful work has stalled. Before stopping anything, you need to identify the right process and understand which other activity must remain available.
This lab provides harmless practice workers and an application log. You will inspect process identities, manage a terminal job, stop one selected worker, and extract its diagnostic without touching platform services.
Inspect Processes and Manage a Terminal Job
In this step, you will inspect running processes and compare foreground and background terminal work.
Enter Kali and choose the shared workspace:
kali
cd /home/labex/project
A process is a running program with a process ID (PID) and an owner. ps prints a snapshot. The -e option selects all processes, and -o selects the fields to show:
ps -eo pid,user,args
Look for the prepared Python practice workers and their kali owner. Ignore unrelated platform and container processes.
top normally refreshes continuously. -b selects a printable batch view, while -n 1 limits it to one update:
top -b -n 1
This shows a resource snapshot rather than leaving you inside an interactive display. PIDs and resource values vary.
A foreground command occupies the terminal until it finishes. sleep waits for a number of seconds without producing output. Start a deliberately long wait:
sleep 30
Press Ctrl+C to interrupt this foreground command and return to the prompt. Ctrl+C is useful when you need to stop the command currently occupying your terminal.
The trailing & starts a command in the background, allowing the shell to accept more commands immediately. Start one disposable timer:
sleep 300 &
The shell prints a job number such as [1] and a PID. jobs -l lists background jobs belonging to this shell and includes their PIDs:
jobs -l
You should see the sleep 300 job running. Leave it alive for this step's check. Keep the same terminal open for the next step; job numbers belong to this shell session.
Stop Only the Stalled Worker and Read Its Log
In this step, you will stop a selected practice process, preserve another worker, and save the relevant error lines.
In the same Kali shell, stop the disposable background timer. kill sends a signal; its default termination signal requests that a process exit. The %1 job reference addresses the first job created in this fresh shell:
kill %1
The shell may print a termination notice. For a process not started as one of your shell jobs, identify its PID first. pgrep -a prints the PID and full command line of matches; -f matches against the full command line:
pgrep -af stalled-worker.py
The relevant command is python3 /opt/labex/stalled-worker.py. This is a harmless training worker that waits indefinitely. The separate training-heartbeat.py worker must remain running.
You can pass a discovered PID to kill with command substitution. $(...) runs the inner command and substitutes its output; double quotes keep that output as one argument. The ^ and $ anchors match the full expected command rather than a broader partial name. Stop only that exact worker:
kill "$(pgrep -f '^python3 /opt/labex/stalled-worker.py$')"
Do this once; repeating it after the worker has exited will find no PID. The command should return without output. Confirm the worker you must preserve is still present:
pgrep -af training-heartbeat.py
Its PID may vary, but its command path should still be listed.
An application log records events in text. The supplied practice log is worker.log; the exercise does not require systemd or kernel-log access. Read the log:
cat /home/labex/project/worker.log
The log mixes informational messages with an ERROR line describing the stalled operation. Use the filtering and redirection already introduced to save only error records:
grep '^ERROR ' /home/labex/project/worker.log > /home/labex/project/worker-errors.txt
cat /home/labex/project/worker-errors.txt
Expected output:
ERROR training request exceeded its time limit
You stopped a selected worker, preserved an unrelated worker, and kept its diagnostic separate from the full log.
Summary
You inspected process IDs, owners, and command lines; observed foreground interruption and background jobs; sent a targeted termination signal; and filtered an application log. You preserved an unrelated worker while stopping the selected stalled process.



