Red Hat / CentOS Check and List Running Services Linux Command nixCraft Updated Tutorials/Posts

How do I list all currently running services in Fedora / RHEL / CentOS Linux server? How can I check the status of a service using systemd based CentOS/RHEL 7.x?

There are various ways and tools to find and list all running services under a Fedora / RHEL / CentOS Linux systems.

Red Hat / CentOS Check and List Running Services Command

Please note that systemd based system such as CentOS/RHEL 7.x and latest version of fedora use the systemctl command to list running services.

List running services using service command on a CentOS/RHEL 6.x or older

The syntax is as follows for CentOS/RHEL 6.x and older (pre systemd systems):
service --status-all
service --status-all | more
service --status-all | grep ntpd
service --status-all | less

Print the status of any service

To print the status of apache (httpd) service:
service httpd status

List all known services (configured via SysV)

chkconfig --list

List service and their open ports

netstat -tulpn

Turn on / off service

ntsysv
chkconfig service off
chkconfig service on
chkconfig httpd off
chkconfig ntpd on

ntsysv is a simple interface for configuring runlevel services which are also configurable through chkconfig. By default, it configures the current runlevel. Just type ntsysv and select service you want to run.

Red Hat / CentOS List Running Services using systemctl (RHEL/CentOS 7.x)

If you are using systemd based distro such as Fedora Linux v22/23/24/26/27/28/29 or RHEL/CentOS Linux 7.x+. Try the following command to list running services using the systemctl command. It control the systemd system and service manager.

To list systemd services on CentOS/RHEL 7.x+ use

The syntax is:
systemctl
systemctl | more
systemctl | grep httpd
systemctl list-units --type service
systemctl list-units --type mount

To list all services:
systemctl list-unit-files
Sample outputs:

Fig.01: List all units installed on the CentOS /RHEL 7 systemd based system, along with their current states
Fig.01: List all units installed on the CentOS /RHEL 7 systemd based system, along with their current states

To view processes associated with a particular service (cgroup), you can use the systemd-cgtop command. Like the top command, systemd-cgtop lists running processes based on their service:
systemd-cgtop
Sample outputs:

Path Tasks %CPU Memory Input/s Output/s / 85 0.3 240.1M - -
/system.slice/NetworkManager.service 2 - - - -
/system.slice/auditd.service 1 - - - -
/system.slice/crond.service 1 - - - -
/system.slice/dbus.service 1 - - - -
/system.slice/lvm2-lvmetad.service 1 - - - -
/system.slice/polkit.service 1 - - - -
/system.slice/postfix.service 3 - - - -
/system.slice/rsyslog.service 1 - - - -
/system.slice/sshd.service 1 - - - -
/system.slice/...tty.slice/getty@tty1.service 1 - - - -
/system.slice/systemd-journald.service 1 - - - -
/system.slice/systemd-logind.service 1 - - - -
/system.slice/systemd-udevd.service 1 - - - -
/system.slice/tuned.service 1 - - - -
/system.slice/wpa_supplicant.service 1 - - - -
/user.slice/user-0.slice/session-2.scope 1 - - - -
/user.slice/user-1000.slice/session-1.scope 4 - - - -

To list SysV services only on CentOS/RHEL 7.x+ use (does not include native systemd services)

chkconfig --list
Sample outputs:

Fig.02: List Sysv based services on systemd
Fig.02: List Sysv based services on systemd

How to check the status of a service using systemd

Say you want to check status of a service named sshd, run
$ systemctl status sshd.service
Sample outputs:

? sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2018-10-15 11:59:40 IST; 4 weeks 0 days ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 1540 (sshd) Tasks: 1 CGroup: /system.slice/sshd.service ??1540 /usr/sbin/sshd -D Nov 06 00:00:00 centos7-box sshd[27878]: Accepted publickey for vivek from 192.168.2.30 port 37785 ssh2: RSA SHA256:GVszs/CD7zRUV6uFCp1c9/8OEgzI5RTD2TvPkglS0AA
Nov 12 14:15:44 centos7-box sshd[29290]: Accepted publickey for backup from 192.168.2.24 port 59226 ssh2: ED25519 SHA256:uym82tbI4l6Gfl+uf/+lfzymbkhstTnAS35lcoa6VLU

One can verify that if a service named sshd is running (active) or not running (inactive) on a CentOS/RHEL 7.x+:
systemctl is-active sshd
systemctl is-enabled sshd
systemctl is-active nginx
systemctl is-enabled nginx
systemctl is-enabled httpd

Check whether a service is running or not running on a CentOS RHEL

Conclusion

For latest version of the CentOS/RHEL 7.x use the systemctl command and for older version try service command to show all services running under Centos or RHEL Server.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Facebook Comments
Spread the love

Posted by News Monkey