Linux get all services

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.

Источник

Red Hat / CentOS Check and List Running Services Linux Command

H ow 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 and RHEL/CentOS 8.x?

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

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements RHEL or CentOS Linux
Est. reading time 6 minutes

Red Hat / CentOS Check and List Running Services Command

Please note that systemd based system such as CentOS/RHEL 7.x/8.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

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

List all known services (configured via SysV)

List service and their open ports

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/8.x )

If you are using systemd based Linux distros such as Fedora Linux v22/23/24/26/27/28/29/30/31 or RHEL/CentOS Linux 7.x/8.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

Источник

how to list all running services in linux from command line

In operating system talk, a service is an application that can be run in the background, usually in perpetuity in order to perform some task or waiting for service requests from other applications to perform tasks. All operating systems, including Linux has some kind of support for these type of applications. Services are also sometimes referred to as daemons.

There are different services that are required for the functioning of an operating system, while others are used by the user. Some common examples of user services are web servers such as Apache or Nginx and database servers such as Oracle or MySql. Some examples of OS specific services are dbus, xdm, network etc.

Most Linux systems have a similar implementation when it comes to running services, but there are still some differences between distros. Many distros also comes with some easy to use GUI applications that allow you to view and manage system services, but not all. We will look at how this can be done from the command prompt.

I should confess that I have exclusively used and worked on Gentoo and have not been keeping up much with the other distros. So, it is quite possible that this post will skew more towards Gentoo but i will try to keep it as generic as possible.

This post solely deals with how to list all services that you are installed or are running on your system. It does not deal with how add, delete or manage the services. I will probably write another post to deal with those functions. I will however describe how to find the status of the service as well, as that somehow corresponds to the reason you might be listing them in the first place.

Systemd or SysV Init/OpenRC

Despite some difference with the commands used to manage the service, most Linux systems have one thing in common. It stores the service related files in the /etc/ folder. The startup scripts for the services are usually in the /etc/init.d/ folder. You might also want to check the /etc/rc.d folder if you do not find the init.d/ folder.

As your system starts up, there needs to be a program or application that finds and launches appropriate drivers and start services. The old and tried system has been SysV init which mainly loaded and ran the startup scripts from /etc/init.d folder. Systemd is a modern day replacement for init and is being adopted by many distros.

It is important that you be aware of what boot system you have, which will help you with finding the startup scripts. A detailed discussion on that topic is probably not for this post.

How to List all Services

As mentioned earlier, most systems keep the startup scripts for the services in the /etc/init.d/ folder. So, a simple listing of the directory contents should show you the list of services that are installed and available to you.

bash$ ls /etc/init.d/

the file names in the folder usually match the name of the service.

One of the most widely used commands to list services and its status is the service command. It could actually be a symlink to the openrc command in some distros, such as Gentoo. So, this could differ between Linux distros, which means you will need to use a command that is specific to your distro or install another utility for it.

Gentoo

In Gentoo, the rc-status command can be used to list the running services. The rc-status command has several useful command line options.

bash$ rc-status —all

–all or -a: This will list all the running or stopped services from all run levels, organized by run level.
–servicelist or -s: This option will list all available services, in a long list
–unused or -u: This will print out the list of services that has not been assigned a run level.

You can use the complementary commands: rc-update, rc-config and rc-service to manage the services in the system.

The Ubuntu distribution and the various other related distros such as Kubuntu, Mint, Xubuntu etc uses Upstart by default instead of the traditional init system, and you can use the service command to list the services. Upstart is a event based system, so the output might vary depending on the state of the system and fired events.

bash$ service —status-all

You can also check the status of a single service, if you know the service name as shown below.

bash$ service mysql status

where mysql is the name of the service.

You can also use the initctl command, which is equivalent to the service command.

bash$ initctl list

Fedora

Fedora does have support for the service utility that was described above, but they recommend the systemctl utility to manage services. The following command will list all the services that running in the system.

bash$ systemctl list-units —type=service

You can check the status of a single service with the same command and different command line arguments.

bash$ systemctl status httpd.service

where httpd.service is the name of the service.

If you have a different distribution that the ones mentioned and the above commands do not work for you then refer to the documentation that is specific to the distro. Also, be sure to execute the above commands with the superuser permissions by using sudo or equivalent.

Ideally, you should disable the services that are not required or being used. You should remove them from the run level as well. It is usually a waste of hardware resources if it running all the time even if it has a small footprint. There is also a possibility of it being a security risk, especially if it has an open port and is listening on it.

Источник

How to List All Running Services in Linux

Linux-based operating systems, like all other operating systems, have processes and services that run while the machine is on. These range from various operating system services, to the command line, to different services/daemons designed to maintain the system and keep it running smoothly. Most services are vital to a process’ normal operation, ranging from helper services to special services designed to handle input, improve performance, offload resources, etc. Processes are also the backbone of a computer’s core functionality, making it important to have the resources for them all.

However, it may occur that a service can run without your knowledge, use up system resources, and even make your system vulnerable if security measures have not been taken into account. Because of possible cases like these, it’s good to know how to check and deal with such cases, as well as have the ability to monitor what processes and services are running on your machine at any moment.

In this tutorial, we will go through several methods of listing/showing all running services and processes on a Linux-based server or machine, as well as go through some useful commands that will help you find and manage these processes and services.

The ‘service’ command line tool

The ‘service’ command comes pre-installed with almost every Linux distribution out there. While its main purpose is to start and stop scripts and create processes, ‘service’ can also be used to see what services are running or stopped at any given moment. Using a simple command, we are given a complete list of services:

When you run this, an output similar to this will appear:

As you can see, a list of services is given as output, with a symbol to the left of the service’s name. A ‘+’ symbol means the service is running, a ‘-‘ means that it is stopped, and a ‘?’ means that the status is not currently known. When this is used in combination with a search tool such as ‘grep’, finding specific services that are running is very easy to do. You can then check the status on a process-by-process basis by entering the status command for a specific process:

This will then output a set of information pertaining to that specific service, including the location of the process, whether or not the service is running, and even the last few lines of the log file from the service.

Short for ‘process status’, PS is a pre-installed utility designed to display information and details about processes. It is a simple, fast tool designed to give quick results with no fuss. With one simple command, we can list a well-detailed list of currently running processes:

You can use this in conjunction with the ‘less’ command to further improve readability. When running this command, we are given details for each process currently running. You can also use the ‘grep’ command to narrow down the results to a specific process name, process ID, and so on.

The ‘top’ command line tool

‘top’ is a built-in tool designed to give an overview of all processes and services currently running on your machine. It is included on both Debian-based and RedHat-based distributions and offers a variety of features to help you figure out what’s happening on your server. You can start ‘top’ by simply writing top on the command line. This is what it should look like:

It can look a bit cluttered, but a lot of this information is very useful. For example, we can see how long the system has been running, the average load, how many users are logged in, how many processes (tasks) are running, sleeping, etc. as well as info on the amount of memory we have in total and available on the server. Top goes into even greater detail, down to a process-specific level. Each column displays a specific value that correlates with the process that is running. We can see who owns the process, how much memory it’s utilizing, how much of the CPU is being utilized, the command name, and the process ID, which is unique to that process and helps us identify it in case there’s more than one of the same process. Using all of this information, we can see exactly what each process is doing, and how many resources each process uses up, all in real-time.

Htop is a lot like ‘top’ in terms of its core features and functionality. It is not usually included in a default operating system install, however, it is available for most if not all Linux distributions through its pre-installed software repositories. Like top, htop allows the user to view detailed information about each process, as well as keep tabs on the system itself. However, htop allows for much finer control over the information displayed to you, as well as offering a suite of utilities that can be applied to processes.

For example, through htop, you can adjust the niceness (the priority) of a process, kill it with varying levels of force, and so on. There’s also sorting, which makes it easier to see only the information that is important to you. Selecting a process is possible using the space bar, making it easier to follow and keep track of a specific process (or processes, since you can select more than one at a time). And with a search function, it’s even easier to check and pay attention to specific processes. Htop even has a bar chart that represents the various system resources, allowing you to easily see how much CPU or RAM is allocated.

Here’s an example of what htop looks like:

With the bars at the top, it’s easy to know how your system is doing with just a glance, along with customizable detailed info available just below them.

By using any of these tools, you can easily find the exact information that you need regarding your services and processes.

PS. If you liked this post on how to see which services are running in Linux, please share it with your friends through social media by using the share shortcuts, or simply leave a comment below. Thanks.

Источник

Читайте также:  Daw что это mac os
Оцените статью