Managing processes and services in Linux
Managing processes and services in Linux involves controlling running applications and system services. Here are some code examples for common process and service management tasks in Linux:
- Listing running processes
To list the currently running processes in Linux, use the ps
command followed by desired options. Here are some examples:
- List all running processes:
ps -ef
ps auxf
- Killing a process
To terminate a running process in Linux, use the kill
command followed by the process ID (PID). Here's an example:
kill 1234
This command will send a SIGTERM signal to the process with PID 1234, asking it to terminate gracefully. If the process does not respond to the SIGTERM signal, you can use the -9
option to send a SIGKILL signal, forcing it to terminate immediately:
kill -9 1234
- Starting and stopping services
To start and stop system services in Linux, use the systemctl
command followed by the desired options. Here are some examples:
- Start a service:
sudo systemctl start service-name
sudo systemctl stop service-name
sudo systemctl restart service-name
sudo systemctl enable service-name
sudo systemctl disable service-name
- Checking service status
To check the status of a running service in Linux, use the systemctl status
command followed by the service name. Here's an example:
sudo systemctl status service-name
This command will display information about the service, including whether it is running or stopped, and any errors or warnings that may be present.
These are some examples of basic process and service management tasks in Linux. There are many more advanced options available, such as managing process priority and resource usage, but these commands should be enough to get you started.
Leave a Comment