- How to check running process in Linux using command line
- Check running process in Linux
- How to manage processes from the Linux terminal
- Linux pgrep command
- Linux top command
- Linux htop command to check running process in Linux
- Linux kill command
- Linux pkill command
- Linux killall command
- Linux nice and renice command
- Command to check services in linux
- Check the service status
- Start the service
- Use netstat to find port conflicts
- Check xinetd status
- Check logs
- Next steps
- Share this information:
- Red Hat / CentOS Check and List Running Services Linux Command
- Red Hat / CentOS Check and List Running Services Command
- List running services using service command on a CentOS/RHEL 6.x or older
- Print the status of any service
- List all known services (configured via SysV)
- List service and their open ports
- Turn on / off service
- Red Hat / CentOS List Running Services using systemctl ( RHEL/CentOS 7.x/8.x )
- To list systemd services on CentOS/RHEL 7.x+ use
- 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 running process in Linux using command line
I am a new system administrator for the Linux operating system. How do I check running process in Linux using the command line option?
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Linux terminal |
Est. reading time | 4 mintues |
One can use the Linux command line or terminal app to display a running process, change their priorities level, delete process and more. This page shows how to use various commands to list, kill and manage process on Linux.
Check running process in Linux
The procedure to monitor the running process in Linux using the command line is as follows:
- Open the terminal window on Linux
- For remote Linux server use the ssh command for log in purpose
- Type the ps aux command to see all running process in Linux
- Alternatively, you can issue the top command or htop command to view running process in Linux
Let us see some example and usage in details.
Please note that vivek@nixcraft:
$ is my shell prompt. You need to type commands after the $ prompt.
How to manage processes from the Linux terminal
The ps command is a traditional Linux command to lists running processes. The following command shows all processes running on your Linux based server or system:
vivek@nixcraft:
$ ps -aux
vivek@nixcraft:
- root – User name
- 1 – PID (Linux process ID)
- 19:10 – Process start time
- /sbin/init splash – Actual process or command
There may be too many processes. Hence, it uses the following less command/more command as pipe to display process one screen at a time:
vivek@nixcraft:
$ ps -aux | more
vivek@nixcraft:
$ sudo ps -aux | less
Press q to exit from above Linux pagers. You can search for a particular Linux process using grep command/egrep command:
vivek@nixcraft:
$ ps aux | grep firefox
vivek@nixcraft:
$ sudo ps aux | grep vim
vivek@nixcraft:
$ sudo ps -aux | egrep ‘sshd|openvpn|nginx’
- 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 ➔
Linux pgrep command
Many variants of Linux comes with the pgrep command to search/find process. The syntax is:
vivek@nixcraft:
$ sudo pgrep sshd
vivek@nixcraft:
$ pgrep vim
vivek@nixcraft:
$ pgrep firefox
vivek@nixcraft:
Linux top command
The top command is another highly recommended method to see your Linux servers resource usage. One can see a list of top process that using the most memory or CPU or disk.
vivek@nixcraft:
$ sudo top
vivek@nixcraft:
Linux htop command to check running process in Linux
The htop command is an interactive process viewer and recommended method for Linux users. One can see a list of top process that using the most memory or CPU or disk and more:
vivek@nixcraft:
$ sudo htop
vivek@nixcraft:
Linux kill command
Want to kill a process? Try kill command. The syntax is:
vivek@nixcraft:
$ kill pid
vivek@nixcraft:
$ kill -signal pid
Find PID using ps, pgrep or top commands. Say you want to kill a PID # 16750, run:
vivek@nixcraft:
$ kill 16750
For some reason if the process can not be killed, try forceful killing:
vivek@nixcraft:
$ kill -9 16750
OR
vivek@nixcraft:
$ kill -KILL 16750
Linux pkill command
If you wish to kill a process by name, try pkill command. The syntax is:
vivek@nixcraft:
$ pkill processName
vivek@nixcraft:
$ pkill vim
vivek@nixcraft:
$ pkill firefox
vivek@nixcraft:
$ pkill -9 emacs
vivek@nixcraft:
$ sudo pkill -KILL php7-fpm
Linux killall command
The killall command kills processes by name, as opposed to the selection by PID as done by kill command:
vivek@nixcraft:
$ killall vim
vivek@nixcraft:
$ killall -9 emacs
Linux nice and renice command
The primary purpose of the nice command is to run a process/command at a lower or higher priority. Use the renice command to alter the nice value of one or more running Linux processes. The nice value can range from -20 to 19, with 19 being the lowest priority. Say, you want to compile software on a busy Linux server. You can set a very low priority, enter:
vivek@nixcraft:
$ nice -n 13 cc -c *.c &
Set a very high priority for a kernel update. Before rebooting Linux server, run:
Источник
Command to check services in 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.
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
Источник
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
Print the status of any service
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 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.
Источник