Gérer les processus : `kill`, `bg`, `fg`
Apprenez à terminer, suspendre et reprendre efficacement des processus depuis la ligne de commande.
Gérer les processus : `kill`, `bg`, `fg` est une leçon Linux Command Line Mastery gratuite sur CoddyKit. Ceci est la leçon 2 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Linux Command Line Mastery, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Linux Command Line Mastery comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
Introduction to Process Control
In Linux, every running program is called a process. Managing these processes is essential for system efficiency and troubleshooting.
This lesson teaches you how to take control of processes: suspending them, sending them to the background, bringing them forward, and even terminating them when they misbehave.
The `kill` Command Basics
The kill command is used to send signals to processes. Its primary use is to terminate processes.
To use kill, you need the Process ID (PID) of the target process. You can find PIDs using commands like ps (covered in a previous lesson).
ps aux | grep sleepGraceful Termination: `SIGTERM`
By default, kill sends the SIGTERM (signal 15) signal. This is a polite request for a process to terminate.
A well-behaved program will catch SIGTERM, perform any necessary cleanup (like saving files), and then exit gracefully.
sleep 30 &
# Use 'ps' to find the PID of 'sleep 30'
# Example: kill <PID_OF_SLEEP>Forceful Termination: `SIGKILL` (-9)
Sometimes, a process might ignore SIGTERM, becoming unresponsive or 'frozen'. In such cases, you need to use a stronger signal: SIGKILL (signal 9).
SIGKILL immediately terminates the process without allowing it to clean up. Use it as a last resort!
sleep 60 &
# Use 'ps' to find the PID of 'sleep 60'
# Example: kill -9 <PID_OF_SLEEP>Suspending Processes with Ctrl+Z
You can temporarily pause a running foreground process using the keyboard shortcut Ctrl+Z.
This sends a SIGSTOP signal, suspending the process and returning control to your shell. The process is still in memory but not executing.
sleep 120
# Type 'sleep 120' and then press Ctrl+Z
# You will see '[1]+ Stopped sleep 120'Listing Jobs with `jobs`
When you suspend a process or send it to the background, it becomes a 'job'. You can list all current jobs managed by your shell using the jobs command.
Each job is assigned a job number, which is useful for referring to it with other commands.
sleep 30
# Press Ctrl+Z
jobsBackgrounding a Job: `bg`
A suspended process isn't running. To make it run in the background (without occupying your terminal), use the bg command.
You can refer to the job by its job number (e.g., bg %1). The process will continue running silently.
sleep 60
# Press Ctrl+Z
jobs
bg %1
jobsForegrounding a Job: `fg`
If you have a process running in the background or a suspended one, you can bring it back to the foreground to interact with it using the fg command.
Like bg, you specify the job number (e.g., fg %1) to bring that specific job to the front.
sleep 60 &
jobs
fg %1
# Press Ctrl+C to stop it or Ctrl+Z to suspend it again.Combining Process Control
These commands work together to give you full control over processes:
- Start a task:
nano - Suspend it:
Ctrl+Z - Move to background:
bg %1 - Start another task:
sleep 100 - Suspend it:
Ctrl+Z - List all jobs:
jobs - Bring
nanoto foreground:fg %1 - Terminate
nano:Ctrl+C - Kill
sleep:kill %2
Quick Check
You've started a program, and it's completely unresponsive. You can't even close it with Ctrl+C. You know its Process ID (PID).
What is the most effective command to immediately terminate this stubborn process?
Recap: Process Control
Great job! You've learned how to manage processes effectively:
kill: Send signals to terminate processes.kill -9: Forcefully terminate a process.Ctrl+Z: Suspend a foreground process.jobs: List background and suspended jobs.bg: Send a suspended job to the background.fg: Bring a background job to the foreground.
These commands are crucial for maintaining control over your Linux environment.
Questions Fréquemment Posées
La leçon « Gérer les processus : `kill`, `bg`, `fg` » est-elle gratuite ?
Oui — le texte complet de « Gérer les processus : `kill`, `bg`, `fg` » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Linux Command Line Mastery, passe à CoddyKit PRO. Le cours Linux Command Line Mastery comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Gérer les processus : `kill`, `bg`, `fg` » ?
Apprenez à terminer, suspendre et reprendre efficacement des processus depuis la ligne de commande. Tu pratiques Linux Command Line Mastery avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Linux Command Line Mastery ?
Aucune expérience préalable n'est requise. Linux Command Line Mastery sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 4.
Combien de temps prend la leçon « Gérer les processus : `kill`, `bg`, `fg` » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Linux Command Line Mastery ?
Oui. Chaque leçon Linux Command Line Mastery inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Comprendre les processus : `ps`, `top`, `htop`
- Gérer les processus : `kill`, `bg`, `fg`
- Surveiller les ressources système : `df`, `du`, `free`
- Priorités des processus avec nice, renice et les signaux