{"id":134,"date":"2025-11-02T12:00:00","date_gmt":"2025-11-02T12:00:00","guid":{"rendered":"https:\/\/rezachegini.com\/?p=134"},"modified":"2026-10-30T06:44:27","modified_gmt":"2026-10-30T06:44:27","slug":"linux-processes-and-signals","status":"publish","type":"post","link":"https:\/\/rezachegini.com\/?p=134","title":{"rendered":"Linux Processes and Signals"},"content":{"rendered":"<p class=\"wp-block-paragraph\">This post explains how Linux handles processes and signals. It shows how to view, stop, and control running programs, find process IDs, and use signals like SIGTERM and SIGKILL safely. It also explains process priority with the nice and renice commands.<\/p><h3 class=\"wp-block-heading\">1. What Are Processes?<\/h3><p class=\"wp-block-paragraph\">A process is a program that is running. Every time you open an app or run a command, Linux creates a process. Each process has:<\/p><ul class=\"wp-block-list\"><li>PID (Process ID): unique number<\/li><li>PPID (Parent Process ID): the process that started it<\/li><li>Owner: the user who runs it<\/li><li>State: running, sleeping, stopped, or zombie<\/li><\/ul><p class=\"wp-block-paragraph\">Example:<\/p><pre class=\"wp-block-code\"><code>sleep 100 &amp;\n# [1] 12345\n# PID is 12345<\/code><\/pre><h3 class=\"wp-block-heading\">2. Viewing Running Processes<\/h3><p class=\"wp-block-paragraph\">To see running processes:<\/p><pre class=\"wp-block-code\"><code>ps\nps aux\nps -ef<\/code><\/pre><p class=\"wp-block-paragraph\">To see processes in real time:<\/p><pre class=\"wp-block-code\"><code>top<\/code><\/pre><p class=\"wp-block-paragraph\">Useful keys in top:<\/p><ul class=\"wp-block-list\"><li>q = quit<\/li><li>k = kill process<\/li><li>P = sort by CPU<\/li><li>M = sort by memory<\/li><\/ul><p class=\"wp-block-paragraph\">Or use htop (easier to read):<\/p><pre class=\"wp-block-code\"><code>sudo apt install htop\nhtop<\/code><\/pre><h3 class=\"wp-block-heading\">3. Finding Specific Processes<\/h3><p class=\"wp-block-paragraph\">To find processes by name:<\/p><pre class=\"wp-block-code\"><code>ps aux | grep nginx\npgrep nginx\npgrep -a python<\/code><\/pre><p class=\"wp-block-paragraph\">To find processes for a user:<\/p><pre class=\"wp-block-code\"><code>pgrep -u reza<\/code><\/pre><h3 class=\"wp-block-heading\">4. Signals \u2013 Controlling Processes<\/h3><p class=\"wp-block-paragraph\">A signal is a message that Linux sends to a process to tell it to do something for example, to stop, reload, or continue. When you press Ctrl + C in the terminal, it sends the SIGINT signal to stop that process.<\/p><p class=\"wp-block-paragraph\">Here are some common signals you will use often:<\/p><ul class=\"wp-block-list\"><li>SIGTERM (15): asks a process to stop nicely. The process can clean up before it ends.<\/li><li>SIGKILL (9): forces a process to stop immediately. It cannot be ignored. Use this only if SIGTERM does not work.<\/li><li>SIGHUP (1): tells a process to reload its configuration file without stopping.<\/li><li>SIGINT (2): interrupt signal (same as pressing Ctrl + C).<\/li><li>SIGSTOP (19): pauses a process.<\/li><li>SIGCONT (18): continues a paused process.<\/li><\/ul><p class=\"wp-block-paragraph\">To see all available signals:<\/p><pre class=\"wp-block-code\"><code>kill -l<\/code><\/pre><p class=\"wp-block-paragraph\">Example:<\/p><pre class=\"wp-block-code\"><code>kill 1234          # sends SIGTERM\nkill -9 1234       # sends SIGKILL\nkill -HUP 1234     # reloads configuration\nkill -STOP 1234    # pauses process\nkill -CONT 1234    # resumes process<\/code><\/pre><h3 class=\"wp-block-heading\">5. Killing or Stopping Processes<\/h3><p class=\"wp-block-paragraph\">Polite stop:<\/p><pre class=\"wp-block-code\"><code>kill 1234<\/code><\/pre><p class=\"wp-block-paragraph\">Force stop:<\/p><pre class=\"wp-block-code\"><code>kill -9 1234<\/code><\/pre><p class=\"wp-block-paragraph\">Kill by name instead of PID:<\/p><pre class=\"wp-block-code\"><code>killall nginx\npkill python<\/code><\/pre><p class=\"wp-block-paragraph\">Be careful -&gt; these commands can stop many processes at once.<\/p><h3 class=\"wp-block-heading\">6. Process Priority (Nice Values)<\/h3><p class=\"wp-block-paragraph\">Every process has a nice value that decides how much CPU time it gets.<\/p><ul class=\"wp-block-list\"><li>Range: -20 (high priority) to +19 (low priority)<\/li><li>Default: 0<\/li><\/ul><p class=\"wp-block-paragraph\">To check:<\/p><pre class=\"wp-block-code\"><code>ps -el\ntop<\/code><\/pre><p class=\"wp-block-paragraph\">Start with a different priority:<\/p><pre class=\"wp-block-code\"><code>nice -n 10 command      # lower priority\nsudo nice -n -5 command # higher priority<\/code><\/pre><p class=\"wp-block-paragraph\">Change a running process:<\/p><pre class=\"wp-block-code\"><code>renice -n 5 -p 1234<\/code><\/pre><h3 class=\"wp-block-heading\">7. Background and Foreground Jobs<\/h3><p class=\"wp-block-paragraph\">When you run commands in the terminal, they usually take control of the screen. But Linux lets you move them to the background so you can keep using the terminal.<\/p><h3 class=\"wp-block-heading\">Run a Process in the Background<\/h3><p class=\"wp-block-paragraph\">Add an &amp; at the end:<\/p><pre class=\"wp-block-code\"><code>command &amp;<\/code><\/pre><p class=\"wp-block-paragraph\">This means the process runs in the background, and the terminal is free for new commands.<\/p><h3 class=\"wp-block-heading\">Pause and Resume a Process<\/h3><p class=\"wp-block-paragraph\">If a process is running in the foreground, press Ctrl + Z to pause it. You can then send it to the background with:<\/p><pre class=\"wp-block-code\"><code>bg<\/code><\/pre><p class=\"wp-block-paragraph\">This resumes the job in the background.<\/p><h3 class=\"wp-block-heading\">Bring a Job Back to the Foreground<\/h3><p class=\"wp-block-paragraph\">To bring a background job back:<\/p><pre class=\"wp-block-code\"><code>fg<\/code><\/pre><p class=\"wp-block-paragraph\">If you have more than one job, you can choose one by its job number (for example, fg %1).<\/p><h3 class=\"wp-block-heading\">See All Background Jobs<\/h3><p class=\"wp-block-paragraph\">To list all current jobs:<\/p><pre class=\"wp-block-code\"><code>jobs<\/code><\/pre><p class=\"wp-block-paragraph\">Example:<\/p><pre class=\"wp-block-code\"><code>sleep 100 &amp;   # run in background\njobs          # show background tasks\nfg %1         # bring job 1 to front<\/code><\/pre><p class=\"wp-block-paragraph\">This system is very useful when you are testing scripts or running long tasks like backups while still using the same terminal.<\/p><h3 class=\"wp-block-heading\">8. Common Scenarios<\/h3><p class=\"wp-block-paragraph\">Kill a frozen process:<\/p><pre class=\"wp-block-code\"><code>ps aux | grep firefox\nkill 1234\nkill -9 1234<\/code><\/pre><p class=\"wp-block-paragraph\">Restart a service:<\/p><pre class=\"wp-block-code\"><code>pgrep nginx\nkill -HUP $(pgrep nginx)<\/code><\/pre><p class=\"wp-block-paragraph\">Stop all Python scripts:<\/p><pre class=\"wp-block-code\"><code>pkill -u $USER python3<\/code><\/pre><p class=\"wp-block-paragraph\">Find high CPU or memory usage:<\/p><pre class=\"wp-block-code\"><code>ps aux --sort=-%cpu | head\nps aux --sort=-%mem | head<\/code><\/pre><h3 class=\"wp-block-heading\">9. Safety Tips<\/h3><ul class=\"wp-block-list\"><li>Never kill system processes like init or systemd<\/li><li>Always try kill before kill -9<\/li><li>Be specific when using pkill or killall<\/li><\/ul><h3 class=\"wp-block-heading\">What I Learned<\/h3><ol class=\"wp-block-list\"><li>Processes are running programs with unique IDs<\/li><li>ps aux and top show what\u2019s running<\/li><li>kill sends signals like stop or reload<\/li><li>SIGTERM (15) is polite, SIGKILL (9) is force<\/li><li>Nice values control process priority<\/li><li>Background jobs use &amp;, bg, and fg<\/li><li>Always use signals carefully<\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>This post explains how Linux handles processes and signals. It shows how to view, stop, and control running programs, find process IDs,&hellip;<\/p>\n","protected":false},"author":2,"featured_media":136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_rezaops_part":"4","_rezaops_linkedin_url":"https:\/\/www.linkedin.com\/pulse\/linux-processes-signals-reza-chegini-malcc\/","footnotes":""},"categories":[10,74],"tags":[78,8,76,83,84],"series":[75],"class_list":["post-134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-linux","tag-command-line","tag-devops","tag-linux","tag-processes","tag-signals","series-linux-fundamentals"],"jetpack_featured_media_url":"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/10\/linux-processes-and-signals-cover.jpg","_links":{"self":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134"}],"version-history":[{"count":1,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/134\/revisions\/135"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/media\/136"}],"wp:attachment":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}