Top 5 Ways to View Linux System Services

Linux system services, sometimes called daemons, are system tasks that are automatically loaded when Linux starts and stopped when Linux exits.

In this article, I will show you how to list all running services in a Linux system and how to check the current status of a service.

Centos/RHEL 7.X's systemd system service view

Starting from CentOS 7.x, CentOS began to use systemd service instead of daemon, and all relevant commands related to the management system startup and management system services were replaced by systemctl commands.

systemctl list-unit-files

The output of the command is as follows:
insert image description here

To view all running systemd services run the following command:

systemctl | more

Besides that, you can also use the following commands:

systemctl list-units --type service

If you want to search for a specific service in the results, you can use pipes and the grep command.

systemctl | grep "apache2"

Use the netstat command to view system services

The netstat command is used to check active network connections, interface statistics analysis, and routing table status. This command is available on all Linux distributions, and we will use it to view system services next.

View services and the ports they listen on:

netstat -pnltu

insert image description here

View system services through the system service configuration file

The service configuration file is /etc/services is an ASCII file that contains a series of services that user programs may use. In this file, the service name, port number, protocol used, and some aliases are included.

For this file, we can use any text tool to view it, such as vim:

vim /etc/services

View systemd service status

In some new versions of Linux systems, systemd has been used to replace the init process. In this kind of system, how to check the system service? We can use the following syntax:

systemctl status service_name

For example, to see if OpenSSH is running on your system, run:

systemctl status sshd

Alternatively, you can also use the following command format to check whether a service is running:

systemctl is-active service_name

If you use this command, the command corresponding to the above example is:

systemctl is-active sshd

insert image description here

At the same time, you can also check whether a service has been enabled, you can use the following command:

systemctl is-enabled service_name

For example, to check whether the OpenSSH service is enabled, you may enter the following command:

systemctl is-enabled sshd

insert image description here

Service status view for earlier versions

In fact, it cannot be said in the early days. There are still many such systems, and the SysV init process is running on them. For this system, the command to view the service status is:

service service_name status

Still an example of checking the status of OpenSSH, the corresponding command is:

service sshd status

insert image description here

You can also use the following command to view the status of all services:

chkconfig --list

The output of the command is as follows:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44388689/article/details/129883235