Sobes.tech
Intern

Πώς ολοκληρώνεται η διαδικασία;

sobes.tech AI

Απάντηση από AI

To terminate a process in Linux, you can use the commands kill, pkill, or killall.

1. Using kill:

  • Ends a process by its Process ID (PID).
  • Requires knowing the PID.
  • Signals:
    • SIGTERM (default, 15): Gentle termination, allows the process to close properly.
    • SIGKILL (9): Immediate and forceful termination, the process cannot ignore this signal.
# find the PID of the process
ps aux | grep <process_name>

# send SIGTERM signal (default)
kill <PID>

# send SIGKILL signal
kill -9 <PID>

2. Using pkill:

  • Ends processes by name or other attributes.
  • Does not require knowing the PID.
  • Supports patterns.
# terminate all processes named 'nginx'
pkill nginx

# terminate all processes containing 'myapp' in their name (case-sensitive)
pkill -i myapp

# send SIGKILL to processes named 'firefox'
pkill -9 firefox

3. Using killall:

  • Ends processes only by their exact name.
  • Does not support complex patterns, unlike pkill.
# terminate all processes with the exact name 'apache2'
killall apache2

# send SIGKILL to processes with the exact name 'mysqld'
killall -9 mysqld

Choice of command:

Command Method of termination Requires PID Pattern support
kill By PID Yes No
pkill By name/attributes No Yes
killall By exact name No No

In most cases, it is recommended to first try to terminate the process using SIGTERM (kill <PID>, pkill <name>), giving it the chance to save data and close properly. SIGKILL (kill -9, pkill -9, killall -9) should only be used as a last resort when the process does not respond to other signals.