Pages

Saturday, February 8, 2025

How to check the services running in background in Linux?

 To check the services running in the background on a Linux system, you can use several commands and tools depending on the information you need. Here are some common methods:

 

1. Using systemctl (for systemd-based systems)

This is the most common way to manage and check services on modern Linux distributions.

• Check all services (active and inactive):

• systemctl list-units --type=service

• Check only active services:

• systemctl list-units --type=service --state=active

• Check the status of a specific service:

• systemctl status <service-name>

Replace <service-name> with the service name (e.g., nginx, ssh).

 

2. Using service Command

For older Linux distributions that use init instead of systemd.

• Check the status of a specific service:

• service <service-name> status

• List all available services and their status:

• service --status-all

 

3. Using ps Command

To list all running processes, including services:

• View all running processes:

• ps aux

• Filter for a specific service or process:

• ps aux | grep <service-name>

 

4. Using top or htop

To monitor active processes in real time:

• Using top:

• top

• Using htop (requires installation):

• htop

These tools display active processes, including services, along with CPU and memory usage.

 

5. Using netstat or ss (for network-related services)

To check network-related services and their ports:

• Using netstat (requires installation on some distributions):

• netstat -tuln

• Using ss (modern alternative to netstat):

• ss -tuln

These commands show services listening on network ports.

 

6. Using chkconfig (for init-based systems)

To check services configured to start on boot (legacy systems):

• List all services and their run levels: 

• chkconfig --list

 

7. Using pgrep

To find processes by name:

• Search for a specific service: 

• pgrep -l <service-name>

 

8. Using rc-service (for OpenRC-based systems)

For distributions like Alpine Linux:

• Check the status of all services:

• rc-status

• Check the status of a specific service:

• rc-service <service-name> status

 

9. Using docker or kubectl (for containerized services)

If services are running in containers, use:

• Docker:

• docker ps

• Kubernetes:

• kubectl get pods

 

Summary

• Modern systemd-based systems: Use systemctl.

• Older init-based systems: Use service or chkconfig.

• Real-time monitoring: Use top or htop.

• Network services: Use netstat or ss.


No comments:

Post a Comment