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.
| Command | Shows | Use it when |
|---|---|---|
| ps aux | Every process on the machine | You want to search with grep |
| top | A live view, busiest first | Something is slow and you want to know what |
| htop | The same, but readable | If it is installed — it usually is not by default |
| jobs | Only what this shell started | After suspending something |
| kill 4821 | Ask a process to stop | Nearly always |
| kill -9 4821 | Make it stop, immediately | Only 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.
ps aux | grep something من الدرس 14 هو كيف تجد PID عمليًا — وتذكّر أن grep نفسه سيظهر في النتائج.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 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 + C يرسل الطلب المهذب نفسه إلى ما يعمل أمامك. وهذا كل ما فعله قط.
-
Ctrl + Z suspends it — the process stops but stays alive, and you get your prompt back. It is not closed, which surprises people. Ctrl + Z يعلّقه — فتتوقف العملية وتبقى حية، ويعود إليك المِحَث. وهي ليست مغلقة، وهذا يفاجئ الناس.
-
fgbrings a suspended job back to the front;bglets it carry on in the background;jobslists what you have suspended.fgيعيد مهمة معلّقة إلى المقدمة؛ وbgيتركها تكمل في الخلفية؛ وjobsيسرد ما علّقته. -
Ending a command with
&starts it in the background straight away:./long-job.sh &returns your prompt at once.وإنهاء أمر بـ&يبدؤه في الخلفية مباشرة: فـ./long-job.sh &يعيد إليك المِحَث فورًا.
kill -9 أولًا. فالبرنامج الذي أُعطي الإشارة المهذبة يحتاج عادةً ثانية أو اثنتين لينهي الكتابة ويخرج؛ وقتله في تلك اللحظة هو كيف ينتهي ملف مبتورًا أو قاعدة بيانات غير متسقة. أرسل kill العادي، وانتظر ثوانٍ، وتحقق هل ما تزال موجودة، وعندها فقط صعّد. وعلى خادم، هذا هو الفرق بين إعادة تشغيل خدمة واستعادة نسخة احتياطية.
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.
pkill nginx يقتل بالاسم لا بالرقم، وهو مريح وخطر بالقدر نفسه — إذ يطابق كل عملية يحوي اسمها ذلك النص. وnohup command & يبدأ شيئًا يظل يعمل بعد انقطاعك، وهذا يهم في اللحظة التي تعمل فيها عبر ssh في الدرس 21.top السؤال في ثلاث ثوانٍ: فالقائمة مرتبة باستخدام المعالج، والمتهم أول سطر. واضغط q للمغادرة، المفتاح نفسه كـless. وإن كانت عملية لا تستخدم معالجًا والجهاز ما يزال يزحف، فانظر إلى عمود الذاكرة بدلًا من ذلك.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1. What does Ctrl + Z do?
The process is still there, listed by jobs. fg brings it back and bg lets it continue in the background.
jobs. وfg يعيدها وbg يتركها تكمل في الخلفية.
2.
Why try kill before kill -9?
kill قبل kill -9؟-9 cannot be caught. Whatever the process was in the middle of writing stays half-written, which on a database is expensive.
-9. وما كانت العملية في وسط كتابته يبقى نصف مكتوب، وهو مكلف على قاعدة بيانات.3. The machine is slow. What is the fastest way to find out what is responsible?
top sorts by processor use and updates live, so the culprit is on the first line. ps aux gives a snapshot with no ordering.
top باستخدام المعالج ويحدّث حيًا، فالمتهم في أول سطر. أما ps aux فيعطي لقطة بلا ترتيب.Score / النتيجة: 0 / 3
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 أولًا