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

In this article, Ryo shows you how to list all the running services on your Linux system and how to check the current status of a service.

Centos/RHEL 7.X Systemd system service Query

CentOS 7.x starts to use systemd services instead of daemons. The commands used to manage system startup and services are replaced by systemctl commands.

systemctl list-unit-filesCopy the code

The following output is displayed:

To view all running Systemd services, run the following command:

systemctl | moreCopy the code

The following output is displayed:

In addition, you can use the following commands:

systemctl list-units --type serviceCopy the code

The following output is displayed:

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

systemctl | grep "apache2"Copy the code

The following output is displayed:

Run the netstat command to view system services

The Netstat command is used to check active network connections, interface statistics, and routing table status. This command is available on all Linux distributions, and we’ll use it next to look at system services.

To view services and the ports on which they listen:

netstat -pnltuCopy the code

The following output is displayed:

View system services in the system service configuration file

The configuration file for the service is /etc/services. It is an ASCII file that contains a list of services that may be used by user programs. In this file, it contains the service name, port number, protocol used, and some aliases.

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

vim /etc/servicesCopy the code

The following output is displayed:

View the Systemd service status

On newer Linux systems, some have replaced the init process with systemd. In such a system, how do you view system services? We can use the following syntax:

systemctl status service_nameCopy the code

For example, to check whether OpenSSH is running on your system, it can run:

systemctl status sshdCopy the code

The following output is displayed:

Alternatively, you can use the following command format to see if a service is running:

systemctl is-active service_nameCopy the code

Using this command, the command that implements the above example would be:

systemctl is-active sshdCopy the code

The following output is displayed:

You can also check whether a service has been enabled by using the following command:

systemctl is-enabled service_nameCopy the code

For example, to check whether the OpenSSH service is enabled, run the following command:

systemctl is-enabled sshdCopy the code

The following output is displayed:

View the service status of earlier versions

In the early days, there are still many such systems running SysV init. For such a system, the command to view the service status is:

service service_name statusCopy the code

To check the OpenSSH status, run the following command:

service sshd statusCopy the code

The following output is displayed:

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

chkconfig --listCopy the code

The following output is displayed:

I am good xu, the world’s top 500 foreign companies Linux development engineer, specializing in the production of Linux dry goods. Welcome to pay attention to my public number “liang Xu Linux”, reply “1024” to obtain the latest and most complete technical information, reply “into the group” into the master such as cloud technology exchange group.