What services are running linux

What services are running linux

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.

Читайте также:  Что делать если версия windows не прошла проверку

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 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:

Читайте также:  Linux mint подключенные диски

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 do I find out what network services are running or listing under Linux?

Q. How do I find out what network service are running under Linux operating system?

A. For security reason it is necessary to find out what services are running. With the help of netstat command, you can print information about the Linux networking subsystem including running services. It can display program name and PID for each socket belongs to. Use netstat as follows:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

  • -t : Select all TCP services
  • -u : Select all UDP services
  • -a : Display all listening and non-listening sockets.
  • -p : Display the PID and name of the program to which each socket belongs

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Bash check if process is running or not on Linux / Unix

Bash check if process is running or not

Bash commands to check running process:

  1. pgrep command – Looks through the currently running bash processes on Linux and lists the process IDs (PID) on screen.
  2. pidof command – Find the process ID of a running program on Linux or Unix-like system
  3. ps command – Get information about the currently running Linux or Unix processes, including their process identification numbers (PIDs).

Let us see some examples about checking processes that running or not in Linux and Unix systems.

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

What is a Linux or Unix process?

A Linux process is nothing but an executing (i.e., running) instance of a program. For example, Apache or Nginx web server runs on Linux or Unix-like system to display web pages in the background. All running process in the background is called as Daemon. So Apache/Nginx is a class of processes that run continuously in the background, and we say nginx or httpd daemon is running on the server. However, how do you verify that Nginx or HTTPD is running? You need to use the commands.

Is nginx process is running or not?

Bash check process running with pidof command

The syntax is:
pidof program
pidof httpd
pidof mysqld
pidof nginx

Bash shell check if a process is running or not with ps

Again the syntax is:
ps -C daemon
ps -C nginx
ps -C httpd
It is common to use the grep command or egrep command with ps as follows:
ps aux | grep nginx
ps aux | egrep -i «(nginx|httpd)»

Читайте также:  Сетевое программное обеспечение windows

Determine whether a process is running or not using a shell script

Each Linux or Unix bash shell command returns a status when it terminates normally or abnormally. You can use command exit status in the shell script to display an error message or take some sort of action. You can use special shell variable called $? to get the exit status of the previously executed command. To print ? variable use the echo command:
pgrep -x mysqld
echo $?
pgrep -x nginx
echo $?
pidof httpd
echo $?
ps -C httpd
echo $?

A 0 exit status means the command was successful without any errors. A non-zero (1-255 values) exit status means command was failure.

Linux/Unix bash command to determine if process is running

It is now easy to check if the process was found or not using exit status value:

Click to enlarge

Bash shell script to check running process

Bash if..else..fi statement allows to make choice based on the success or failure of a command:

A note about service and systemctl command

One can use systemctl command to control the systemd system under Linux. It can provide status of service too. For example, find out if nginx is running or out, run:
systemctl status
systemctl status sshd
systemctl status nginx
Older Linux distros and Unix like system such as FreeBSD use service command for the same purpose. The syntax is:
sudo service status
sudo service nginx status
sudo service sshd status

Conclusion

You learned how to determine whether a process is running or not and use a conditional shell script to start/stop process based on that condition. See pgrep and bash man page here for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Thank you for this article, it helped me a lot to check if a program that I run in rc.local (Raspberrry) was working or not and to check for how long it is running.

I have a trouble with the continuity of this program running. It starts automatically with the raspberry start on, but frequently the program stop working and close (never run more than two days).

I was thinking about to handling this error rebboting the system programatically every hour for example.

Could you help me to find out where to looking for a solution or if it is possible to check by a routine(code) if the program is running or not as a condition to reboot or not the system?

Источник

Оцените статью