Interview Prep/Linux/Processes, services and systemd

A cron-started process spawns children that keep running after the parent is killed. How do you clean this up properly?

AdvancedScenarioProcesses, services and systemd
Answer

Situation read → Orphaned process trees; you need group or cgroup-wide termination.

What I'd do →

  1. Now: find the process group/session and kill it:
ps -eo pid,pgid,sid,cmd | grep job
kill -TERM -- -<PGID>
  1. Long term: run the job as a systemd service/timer, so systemctl stop kills the whole cgroup (KillMode=control-group, default).

Why → Signals sent to one PID don't reach its children; cgroups contain every descendant.

Interview tip → The minus sign in kill -- -PGID targets the process group, a detail interviewers like.

All Linux questions Roadmap: Linux

More on Processes, services and systemd