- Linux check if service running
- Check the service status
- Start the service
- Use netstat to find port conflicts
- Check xinetd status
- Check logs
- Next steps
- Share this information:
- How to List Services in Linux
- Check and Listing linux services (systemd on Centos/RHEL 7.x)
- Listing services using Netstat Command
- Viewing /etc/services file
- Systemd services status check
- Checking the status of services in older systems (Centos/Rhel 6.x)
- How to check all running services in Linux
- Method-1: Listing Linux Running Services with service command
- Method-1(a): How to check running services in System V (SysV) init System
- Method-1(b): How to check running services in Linux with pstree command
- Method-2: How to check running services in systemd system using the systemctl command
- Method-2(a): Listing Linux services with pstree command
- Method-2(b): Listing Linux Services with chkservice command
- Conclusion
- How to check all the running services in Linux
- How to check running services in Linux
- System V(SysV) | Upstart | Systemd
- System V (SysV)
- Upstart Init System
- Systemd
- Check all running services in a System V(SysV) init system
- Check all running services in an Upstart init system
- Check all running services in a Systemd init system
- Conclusion
Linux check if service running
Last updated on: 2019-12-20
Authored by: Rackspace Support
When you need to troubleshoot a network service, the first step is to ensure that the service is running.
If the service has an initialization (init) script installed, you can use the service command to start, stop, and check the status of the service. This command references a service by using its init script, which is stored in the /etc/init.d directory for Debian®-based distributions and the etc/rc.d/init.d directory for Red Hat®-based distributions.
If you don’t know the name that the system uses for a service, check either of the preceding directories by using the ls command followed by the directory name. Some names vary depending on your distribution. For example, Apache® is httpd on CentOS® and apache2 on the Ubuntu® operating system.
Note: Many newer Linux® distributions use systemd instead of netstat to check services. If you’re using systemd , replace all service commands with systemct1 . For more information about systemct1 commands, see the Fedora™ SysVinit to Systemd Cheatsheet.
Check the service status
A service can have any of the following statuses:
- start : The service has started.
- stop : The service has stopped running.
- restart : The service is rebooting and will start after the process is complete.
The following example shows how to check the status of httpd on CentOS by using the service command:
Start the service
If a service isn’t running, you can use the service command to start it. The following example starts the httpd service:
If the application can’t be started, the system reports the failure and usually displays a message that indicates the cause of the problem.
Use netstat to find port conflicts
In the preceding example, httpd can’t be started because something is already listening on the port. To find out what’s listening, you can run the netstat command.
Run the following command to display a list of listening programs and the ports that they’re using:
The output shows that the nc program (which appears in the Program name column) is listening on port 80 (which appears in the Local Address column). Stopping this program should enable httpd to be started.
Note: For more information about the netstat command, see Check listening ports with netstat.
Check xinetd status
If the service isn’t running, it might be because a super-server such as an Extended Internet Service Daemon ( xinetd ) is being used to launch the program when a connection is received. If this is the case, starting the service might have resolved the issue. Run the following command to verify that the issue is resolved:
Check logs
If you can’t start your service, review your logs to see if they contain information about the issue.
Next steps
After you’re sure that the application is running, check the server resources to verify how much your application is consuming.
Share this information:
©2020 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
Источник
How to List Services in Linux
In this article, I will show you how to list all running services on Linux. We will also check how to check the status of a service on a systemd system.
Let’s learn different commands used to list services on Centos/RHEL 7.x.
Check and Listing linux services (systemd on Centos/RHEL 7.x)
To list systemd services we will use systemctl command as below
Sample Output
To list active systemd services run
Sample Output
Another command you can use is
Sample Output
You can pipe the output to grep to search a more specific service as shown below
Output
Listing services using Netstat Command
Nestat command is a tool used for examining active network connections, interface statistics as well as the routing table. It’s available in all Linux distributions and here we will check how to list services using netstat command.
To check the services alongside the ports they are listening.
Output
Viewing /etc/services file
The /etc/services is an ASCII file that contains information about numerous services that client applications might use on the computer. Within the file is the service name, port number and protocol it uses, and any applicable aliases. ITO put t indicates whether a service is TCP or UDP and the name it goes by according to IANA. This information is helpful especially if you are unsure which service is running on which port by default.
To get a clearer picture, view the /etc/services file using a text editor of your choice.
Output
Systemd services status check
In newer versions of Linux, Systemd init is present. To check if a service is running, use the syntax below
Syntax
For example, to check if OpenSSH is running on your system, run
Output
Alternatively, you can use the syntax below to check if the service is active
In this case, to check if OpenSSH is active, execute
Output
Also, you can use the command below to check if a service is enabled
To check if OpenSSH is enabled, run
Output
Checking the status of services in older systems (Centos/Rhel 6.x)
For systems running SysV Init, you can check the status of services by running
For example, to check the status of OpenSSH, run
Output
You can also check all services by running
Output
We hope you found this article useful. Feel free to try out some of the systemd commands listed here.
Источник
How to check all running services in Linux
There are many ways as well as tools to check and list all running services in Linux.
Most Linux administrators typically use ‘service service_name status’ or ‘/etc/init.d/service_name status’ for the System V (SysV) init system, and ‘systemctl status service_name’ for the systemd systems for a specific service.
The above commands show whether the particular service is running on the server or not. These are frequently used commands by every Linux administrator.
If you are new to the environment and want to know what services are running on the system, continue to read.
The following commands lists all the services running on the system and give you an idea of what purpose the system is being used for. Also, it provides an opportunity to disable certain services that are not used on the system.
‘init’ (short for initialization) is the first process started during booting of the computer system. init is a daemon process that continues running until the system is shut down.
We recommend reading the following articles related to this topic.
Many init systems have been developed for Linux, but the following are the three most familiar and commonly used init systems.
- System V (Sys V) is the older init system
- Upstart is an event-based replacement for the traditional init system
- systemd is the new init system, that was adopted by most of the latest Linux distributions
Method-1: Listing Linux Running Services with service command
To display the status of all available services at once in the System V (SysV) init system, run the service command with the —status-all option:
If you have multiple services, use file display commands (like less or more) for page-wise viewing. The following command will show the below information in the output.
- Running services and their associated PID
- Stopped services
- Configured iptables rules
- Configured and active network interface information.
Run the following command to see only running services in the system.
Run the following command to see the specified service status. For instance, use the following command to check the Apache Web server status on a RHEL based system.
To determine the current status of a particular service, execute the following command.
Use the following command to see a list of services that were enabled on boot. These services will be kicked on as part of the system boot process.
Method-1(a): How to check running services in System V (SysV) init System
Alternatively, you can view services running on a Linux system by issuing the ‘initctl’ command as shown below.
Method-1(b): How to check running services in Linux with pstree command
Run the ‘pstree’ command without any additional parameter to see services running in the Linux system:
Method-2: How to check running services in systemd system using the systemctl command
‘systemctl’ command allows users to check and list all services running in a Linux system that uses “systemd” as the system manager.
- UNIT Describe about the corresponding systemd unit name.
- LOAD Describes whether the corresponding unit currently loaded in memory or not.
- ACTIVE Indicate whether the unit is active or not.
- SUB Indicate whether the unit is in running state or not.
- DESCRIPTION A short description about the unit.
To see loaded service in the system, use the list-units subcommand and the —type switch with a value of service. It shows active, running, exited or failed services in the output.
Run the following command to view a particular service status.
Detailed information about a particular service can be verified with the systemctl command as shown below.
Run the following command to view the services running on the system with the systemctl command:
Use the below command to see which services were enabled on boot:
systemd-cgtop shows top control groups by their resource usage such as tasks, CPU, Memory, Input, and Output:
Method-2(a): Listing Linux services with pstree command
List of services running in a Linux system can be verified using the ‘pstree’ command as shown below.
Method-2(b): Listing Linux Services with chkservice command
chkservice is a new tool for managing systemd units in terminal. It requires super user privileges to manage the units.
To view the help page, hit ‘?’ button. This will show you available options to manage the systemd services.
Conclusion
This article explained several ways to check and list all running Linux services.
If you have any questions or feedback, feel free to comment below.
Источник
How to check all the running services in Linux
When using Linux, many processes and services run in the background, some with your knowledge and some may be malicious and run without your permission. In this post, we look at all the best ways to list the services running on the Linux system.
W hen using any Linux distribution, some processes and services run alongside. Some can be running in the background even without users’ knowledge. Having unnecessary services running can consume much of the system resources or also pose a security issue if measures are not put into consideration.
Therefore, there comes a need to know all the running services on your system. In this article, we look at all the possible ways which you can use to list running services on your Linux machine.
How to check running services in Linux
Let us first get a good understanding of Linux services. If a service has an initialization – script , then it comes with three statuses:
All which are executed with the – service command. For example, to restart the network-manager service, run the following command:
The service command references each service using the init script stored in /etc/init.d for Ubuntu and any other Debian-based distro, and etc/rc.d/init.d for RedHat-based Linux distributions. Some service name varies from one distribution to another. For example, the Apache webserver service is httpd on CentOS and Apache2 on Ubuntu.
System V(SysV) | Upstart | Systemd
A lot of Linux distros fall under of the following init systems:
- System V, which was the initial init system.
- Upstart
- systemd, which is the latest init system as of writing this article.
System V (SysV)
System V or commonly known as SysV is an old init system used by older Linux distributions and dates back to the original Unix. SysV manages the startup process using shell script present in the /etc/init*. In case you are using /etc/init.d/sshd start to start or stop a service; then you are using on a System V system.
Upstart Init System
It is an event-based init system which served as a replacement for the /sbin/init daemon. Upstart init system was used to manage the start and stopping of services during boot, shutdown, and supervising them while the system is running. Upstart was initially developed for Ubuntu Linux distro to replace the old System V used in other older distributions.
Systemd
It is the new init system that most Linux distros are moving to. It was developed to speed up the boot process, managing dependencies, and much more. In case you are using systemctl restart sshd start to start or stop a service, then you are using on a Systemd system.
Check all running services in a System V(SysV) init system
Let’s look at some of the Terminal commands you can use to list all running services in a SysV init system.
service –status-all command output
The above command lists all the running services in your system. In case the services running are many, you can use additional parameters – more and less to list the services in an organized and clear view.
service –status-all | Less command output
service –status-all | More command output
To list only services currently running on the system, execute the command below:
To view the status of a particular service, execute the command below:
Alternatively, you can execute the command below to view the status of a particular service.
To list all the services enabled in the boot, execute the command below:
Check all running services in an Upstart init system
To list all services running on a Linux system running Upstartinit system, execute the command below:
Check all running services in a Systemd init system
To list all running services on a Linux system running Systemd init system, execute the command below:
systemctl command output
From the above command, we see that the data is displayed in five columns, namely, UNIT, LOAD, ACTIVE, SUB, and DESCRIPTION. Let’s look at what each column stands for:
- UNIT – Shows the corresponding Systemd unit name.
- LOAD – This column displays whether the current unit is loaded on memory or not.
- ACTIVE – This column indicates whether the unit is in use (active) or not.
- SUB – Describes the running state of a particular unit.
- DESCRIPTION – Gives a detailed description of a particular unit.
You can also list running services based on their type using the command below:
systemctl list-units –type service
You can also list services based on their current state. It is relatively similar to the output of the previous command but a little more straightforward.
systemctl list-unit-files | grep enabled
To list the status of a particular service, execute the command below:
systemctl status acpid.path
To list only services currently running on the system, execute the command below:
systemctl | grep running command
To list all services enabled in the boot, execute the command below:
systemctl list-unit-files | grep enabled command
You can also view top control groups and their system resource usage such as I/O, CPU, Tasks, and memory using the systemd-cgtop command.
systemd-cgtop command output
We can also use pstree to list all running services in the system. Pstree captures this information from Systemd system output.
pstree command output
The pstree can also be used with System V int system. It captures output from the SysVinit system.
You can also use chkservice utility to check all running services in a Systemd system. It does not come pre-installed. However, you can install via Terminal using the command below:
Install chkservice command
To start chkservice, execute the command below. Note, you require superuser privileges.
start chkservice Terminal command
To see all the features that come with this fantastic tool, press the [?] key. It opens the help menu.
Press ? to view help menu – chkservice
Conclusion
These are some of the commands and utilities you can use to check all running services on your Linux system. If you have a command or tool that we have not discussed in this post, feel free to let our readers know in the comment section.
Источник