--- title: 5. Process & Job Control collection: linux author: Akash Kadlag updated: 2026-10-20 source: https://docs.chaicode.com/linux/process-job-control --- # 5. Process & Job Control ![Welcome](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/200db52ba60da30585129339513604f2929ca6b1f85075e35738d689e4d72061.png) Welcome ![Drawn comparison: an app icon sitting inside a phone drawer vs a live delivery biker icon moving across a map in RAM.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/f90d73516d2ac542efc4662d884e9a9f9a6ea695cf40924b203be998289bc7ff.png) Files vs Processes — • A file is data resting on disk — like the Zomato app sitting installed on your phone. • A process is code actively running in RAM — like tracking your live Biryani order. • Files are nouns (stored on SSD); processes are verbs (executing right now). • One program binary can spin up multiple independent running processes. ![A digital ID card layout displaying fields for PID #4521, Parent PID, Owner 'deploy', and a resource usage meter.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/0da69aad04e4a359a915f9d12da24de876f8c6927b0d1b8a7bf2a0620fa340d4.png) Every Process Has an Identity — • PID (Process ID): A unique tracking number, just like a 12-digit UPI reference ID. • PPID (Parent PID): The process that spawned it. • User: The account running it (deploy, ubuntu, or root). • State: Running, sleeping, stopped, or zombie. • Resources: Live percentage of CPU and RAM being consumed. ![A hierarchical family tree diagram branching downwards from 'PID 1 (systemd)' to bash shells and sub-processes.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/0b54801066d1ced59c878663a44866285a4d04bb37fec2595fb995abf702f386.png) The Family Tree: PID 1 — • Every single process is launched by another parent process. • Open bash and run a script → bash is the parent, your script is the child. • Follow the family tree all the way up and you reach PID 1: systemd. • systemd is the root ancestor of every task running on modern Linux. ![A camera taking a freeze-frame snapshot of a terminal table highlighting PID, CPU%, and command names.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/2fc7fe5052598bfba6275332e851d4fafc496b4ebed54c01943c4b5a9e53021b.png) Taking a Snapshot with ps — • ps gives an instant snapshot of running tasks — like checking your PhonePe passbook. • ps aux shows every active process across all users on the server. • Key columns: USER, PID, %CPU, %MEM, and COMMAND. • Look at TTY: a '?' means a background service running detached from any terminal. ![A live sports-style dashboard showing multi-core CPU bar graphs with green/yellow/red load meters.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/385d52a4d2c9cb1be1ec9b4558e9ce82e3d76599475f99e7aad779e91a9cd77e.png) Live Monitoring with top & htop — • When your server feels slow during an IPL match rush, open top or htop. • htop gives a real-time, colour-coded dashboard of CPU cores and RAM. • Easily find runaway scripts hogging 100% CPU. • Useful shortcuts in htop: F4 to search/filter, F6 to sort, F9 to terminate. ![A two-lane road: a car blocking the main lane (foreground) versus a scooter moving freely on the side lane (background).](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/610dc6fa2e335c009ce533f1ad1bff94943ec222960c174e398f508f6a1a7ba6.png) Foreground vs Background — • Foreground: Command locks your terminal until it finishes (like waiting on an OTP screen). • Background with '&': Appending '&' frees up your shell immediately. • Use Ctrl+Z to freeze a stuck task, then type 'bg' to let it run in the background. • Catch: If your terminal closes or SSH disconnects, background child processes usually die. ![Two buttons: a polite doorbell labeled 'SIGTERM 15' and an emergency pull-cord labeled 'SIGKILL -9'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/885a5bb76daaf4f9494c64291cadd3269a1104235136f4b4d20125902e14eeb9.png) Controlling Processes: kill Signals — • 'kill' doesn't destroy immediately; it sends a polite or forced signal. • SIGTERM (-15): Polite request ('Please wrap up and close cleanly'). Always try this first. • SIGKILL (-9): Emergency power cut ('Die instantly'). Gives zero chance to save open files. • SIGHUP (-1): Asks a service to reload its configuration without stopping. ![A 24x7 security guard at a building reception booth rebooting a tripped power switch automatically.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/2eaa653d14d0c8ae4e5403dbee109a4f497013ee116ef9ccfbc47d891981c828.png) systemd: The Service Manager — • systemd is PID 1, starting immediately when the Linux kernel boots up. • Its main job: Manage background daemons (.service unit files). • It starts services in order, monitors their health, and collects logs. • If your app crashes or the machine restarts, systemd automatically revives it. ![A neat 3-section blueprint document labeled Unit, Service, and Install with callout notes.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/5d3eb52b080aca8a463e2dc26aefb6b124ea9a47b629c1d76bae2d405dd42a19.png) Anatomy of a Unit File — • Unit files live in /etc/systemd/system/ (e.g., myapp.service). • [Unit]: Metadata, description, and startup order (e.g., After=network.target). • [Service]: What command to run, under which user, and restart policies. • [Install]: Defines run states — WantedBy=multi-user.target ensures it boots with the OS. ![A recipe card with ingredients checked off: Absolute Path, Non-Root User, Restart Rules, and a locked secret file.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/bc67d9720aa4c15573efdb9de34cfb54b592b4b913e57baa41a2bc8341f8cbbb.png) Writing the [Service] Block — • ExecStart: Must use full absolute paths (e.g., /usr/bin/python3, never plain python3). • User: Run as a standard user (e.g., deploy), never as root unless essential. • Restart=always: Auto-revives your app on crashes. • RestartSec=5: Waits 5 seconds before restarting to prevent endless crash loops. • EnvironmentFile: Loads sensitive API keys safely from an external file. ![Two switches: an instant toggle button labeled 'Start Now' and a calendar repeating icon labeled 'Enable at Boot'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/efa387707635768e7daa280b6affc4a65a966dfa7dccc75aeea295f9f50a41b1.png) systemctl: Start vs Enable — • 'start' runs the service right now; it won't survive a reboot (like booking a single Uber ride). • 'enable' sets it to start automatically on every server boot (like a daily milk subscription). • Best practice for production: run 'sudo systemctl enable --now myapp'. • 'restart' stops and boots fresh (brief downtime); 'reload' just re-reads configs. ![A traffic signal indicator showing green for 'active (running)' and blinking red for 'failed'.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/72ea3a34eee0a7e2d9bce4bd9f362ff160af29ee4c8c80b43ce5a96d8f8c13cd.png) Checking Health with systemctl status — • 'systemctl status myapp' shows uptime, memory usage, and recent log snippets. • active (running): Healthy, live, and taking traffic. • active (exited): Ran successfully and finished (normal for one-off setup jobs). • failed: The process crashed or threw an error. • Golden tip: Run 'systemctl --failed' to immediately list broken services on any server. ![A funnel gathering console outputs from multiple running apps into a single searchable digital journal stream.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/3dd2252108d18a8b90e4e589799e90304c7b340867cc4b4a753e797eeefee438.png) Centralized Logs with journalctl — • systemd automatically catches all stdout and stderr logs — no more messy nohup.out. • journalctl -u myapp -f: Streams live logs in real-time, just like live Swiggy delivery tracking. • journalctl -u myapp -n 50: Shows the last 50 log lines. • journalctl -b: Shows all system logs recorded since the current boot. ![Common Mistakes](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/cddd430040ffdb9b622ef82afb30d78ff2789a2cd951cb6f67a6972a06267583.png) Common Mistakes ![A checklist with warning icons next to missing daemon-reload, relative file paths, and plaintext API keys.](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/6315c80adea06e0a4b898ecf5d683f725109a4d54dd83757967ec519ee61a0b7.png) Pitfalls to Avoid — • Edited a unit file? Always run 'sudo systemctl daemon-reload' or changes are ignored. • App crashed on start? Check ExecStart — relative paths fail (code 203/EXEC). • Service died after reboot? You forgot to run 'systemctl enable'. • Storing payment gateway keys in the unit file? Move them to a secure EnvironmentFile. • Jumping straight to 'kill -9'? It risks database and cache corruption; try plain kill first. ![Challenges](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/6b6ec9977873565b9d70bf9fdd82527e6e66b274c31407d68ca587603ea68483.png) Challenges ![Challenge - 1](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/309b40507573a241b692fccc0a3c140312739db7d28c863ffcb664d397a522c0.png) Challenge - 1 ![Challenge - 2](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/0be5f58d037aadbadca20bd77d929cfd29bddf39cd5faa232d4a68f4b1c13439.png) Challenge - 2 ![Challenge - 3](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/679cc12e50b473efe7ca5c566b36d1b7118e808285fd0ffc4eee4a9d9b96a33a.png) Challenge - 3 ![Challenge - 4](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/c5305659b5742a3da1345b8233258adece5bd8f8f40064cb5c7db3a942484aca.png) Challenge - 4 ![Challenge - 5](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/65e963238644d57f607023792916b13421dd1d6a60495e7f18164ff165af2fdd.png) Challenge - 5 ![Challenge - 6](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/6b9817bf0f2fbc6012c06286f434a920f8f0141e160450b7e68ad0b9905a7da6.png) Challenge - 6 ![Bonus](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/4ff117a842d083c3597167bff83790dada6a622bcec43fac6313bc30c68d6904.png) Bonus ![Bonus](https://docs.chaicode.com/cdn-cgi/image/width=1600,format=auto,fit=scale-down/assets/2c3dccbbc5f1b726bc71dd7958c73dbdc78053de17a1974d9104aef77c955fab.png) Bonus