Lesson 19 / الدرس 19

Processes and jobs / العمليات والمهام

Every running program is a process with a number. Knowing how to list them, stop them politely and stop them rudely is what turns "my machine is stuck" into a diagnosis.

كل برنامج عامل عملية لها رقم. ومعرفة كيف تسردها وتوقفها بأدب وتوقفها بفظاظة هي ما يحوّل "جهازي عالق" إلى تشخيص.

A process is one running program. It has an identifying number — a PID — an owner, a parent that started it, and a share of memory and processor time. Your shell is a process; every command you run becomes a new process that the shell started.

CommandShowsUse it when
ps auxEvery process on the machineYou want to search with grep
topA live view, busiest firstSomething is slow and you want to know what
htopThe same, but readableIf it is installed — it usually is not by default
jobsOnly what this shell startedAfter suspending something
kill 4821Ask a process to stopNearly always
kill -9 4821Make it stop, immediatelyOnly when the polite version failed

ps aux | grep something from lesson 14 is how you find a PID in practice — and remember that the grep itself will appear in the results.

Polite and rude ways to stop something

kill 4821         asks politely: finish up and exit
kill -9 4821      tells the kernel to end it, now
The first sends a signal the program can catch, so it can close its files, finish writing and exit cleanly. The second cannot be caught or ignored — the process is removed immediately, with whatever it was writing left half-finished. Run the demonstration for why the order matters.

The keys you already press

  • Ctrl + C sends the same polite request to whatever is running in front of you. That is all it has ever done.
  • Ctrl + Z suspends it — the process stops but stays alive, and you get your prompt back. It is not closed, which surprises people.
  • fg brings a suspended job back to the front; bg lets it carry on in the background; jobs lists what you have suspended.
  • Ending a command with & starts it in the background straight away: ./long-job.sh & returns your prompt at once.

Two related commands you will meet on a server. pkill nginx kills by name rather than by number, which is convenient and dangerous in equal measure — it matches every process whose name contains that text. And nohup command & starts something that keeps running after you disconnect, which matters the moment you are working over ssh in lesson 21.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. What does Ctrl + Z do?

2. Why try kill before kill -9?

3. The machine is slow. What is the fastest way to find out what is responsible?

Your task / مهمتك

Investigate what is running on your own machine. Report the five processes using the most processor time and say what each one is — look up any you do not recognise. Then demonstrate job control for real: start something long, suspend it with Ctrl + Z, show jobs, resume it, and finally stop it with kill.

افحص ما يعمل على جهازك. وأبلغ عن العمليات الخمس الأكثر استخدامًا لوقت المعالج وقل ما كل واحدة — وابحث عن أي واحدة لا تعرفها. ثم اعرض التحكم بالمهام فعلًا: ابدأ شيئًا طويلًا، وعلّقه بـCtrl + Z، وأظهر jobs، واستأنفه، وأوقفه أخيرًا بـkill.

  • Five real processes, each identified خمس عمليات حقيقية، كل واحدة معرَّفة
  • A real suspend, jobs listing, and resume تعليق حقيقي وقائمة jobs واستئناف
  • A process stopped with kill, by its PID عملية أُوقفت بـkill برقمها
  • A sentence on why not kill -9 first جملة عن سبب عدم اللجوء إلى kill -9 أولًا
How do you want to submit? / كيف تريد التسليم؟