In Linux, services (or daemons) are background processes that start during system boot and run until shutdown. They provide essential functions such as networking, printing, and web serving. Proper management of these services ensures system performance, security, and stability.
Ubuntu uses systemd
for service management. It replaces older init systems and provides a standardized method to control services. The systemctl
command is used for managing these services.
To check the status of a service:
sudo systemctl status servicename
Example:
sudo systemctl status apache2
To start or stop a service:
sudo systemctl start servicename
sudo systemctl stop servicename
Example:
sudo systemctl start apache2
sudo systemctl stop apache2
To restart or reload a service:
sudo systemctl restart servicename
sudo systemctl reload servicename
Example:
sudo systemctl restart apache2
sudo systemctl reload apache2
To configure a service to start automatically at boot or prevent it from starting:
sudo systemctl enable servicename
sudo systemctl disable servicename
Example:
sudo systemctl enable apache2
sudo systemctl disable apache2
To view logs for a service:
sudo journalctl -u servicename
Example:
sudo journalctl -u apache2
To list all services and their statuses:
systemctl list-units --type=service
Processes are instances of running programs. Each process is identified by a unique Process ID (PID) and has its own resources and memory space.
To list all running processes:
ps aux
To list processes with additional details and in a hierarchical view:
ps aux --forest
To find a process by name:
pgrep processname
ps -ef | grep processname
Example:
pgrep apache2
ps -ef | grep apache2
To get detailed information about a specific process by PID:
ps -p PID -o pid,ppid,cmd,%mem,%cpu
Example:
ps -p 1234 -o pid,ppid,cmd,%mem,%cpu
To terminate a process:
kill PID
To forcefully terminate a process:
kill -9 PID
Example:
kill 1234
kill -9 1234
Managing both services and processes is crucial for maintaining the performance and stability of a Linux Ubuntu system. By understanding how to control services and manage processes effectively, you can ensure your system operates smoothly and efficiently.