I’m trying to troubleshoot some issues on my Linux server and need to see a list of all running services. Can anyone advise on the commands or tools I should use to get this information? Your help would be greatly appreciated!
You can list running services in Linux using a few different commands or tools, depending on what exactly you’re looking for and which Linux distribution you’re using. Here’s a rundown of some common methods:
-
systemctl: On many modern Linux distributions that use systemd (like Ubuntu, Fedora, and Debian-based systems), you can use
systemctl:systemctl list-units --type=service --state=runningThis will give you a list of all currently running services. If you want to see all services, whether running or not, you can use:
systemctl list-units --type=service -
service command: On some older distributions or those that use init.d, you can use the
servicecommand:service --status-allThis will list all services, with
+indicating running services and-indicating stopped services. -
ps command: If you need a more granular level of detail and want to see all running processes, the
pscommand is your friend:ps -ef | grep service-nameReplace
service-namewith the name of the service you’re interested in. -
htop or top: For a more interactive approach,
htoportopcan be used to view all running processes and their status.htopis more user-friendly but might need to be installed:sudo apt-get install htop htop
One thing to keep in mind is that some services might run under user-level daemons, especially newer applications which can be a bit trickier to track down.
Personally, I always start with systemctl since most distributions nowadays are using systemd, and it gives a pretty comprehensive overview. But don’t ignore the ps command—it can reveal if a service started via an unusual method.
Lastly, knowing your specific distribution can help tailor these commands more precisely to your setup. It’s also a good idea to check logs if you are troubleshooting specific issues, as they can give you more detailed information about what might be failing. For systemd systems, journalctl can be very useful:
journalctl -u service-name
Good luck with the troubleshooting!
Honestly, I think systemctl is overkill for most people. Sure, it works on most modern distributions, but it’s bloated and not that intuitive. If your server is anything other than a fresh install of the latest Ubuntu or Fedora, you might run into quirks or unexpected behavior.
For something straightforward and less prone to issues, consider using chkconfig or netstat.
-
chkconfig - Although it’s more common in Red Hat-based systems like CentOS, it can be quite straightforward:
chkconfig --list | grep '3:on'This will show all the services set to start in runlevel 3. However, be aware that
chkconfigmight be phased out in the latest systems. -
netstat - If you’re troubleshooting network-related services, use
netstatfor a quick check of open ports which services are tied to:netstat -tulnYes,
netstatis somewhat deprecated in favor ofss, but many still find it more convenient.
Lastly, when you need a visual and comprehensive tool but don’t want to hassle with installations or configurations, you can use lsof to list open files and socket connections which often correlate with running services:
lsof -i -P -n
For those still reliant on ps or top, just be aware that they give gobs of data, most of which is irrelevant if you’re looking for running services specifically. It’s like using a sledgehammer to crack a nut—inefficient and over the top.
And watch out for interactive tools like htop. While they are user-friendly, they’re also overhyped. They can be heavy on your terminal sessions and could mislead you into thinking something’s wrong just because it looks busy.
Bottom line: don’t get tangled up with overly complex tools if simpler ones suffice for your needs.
While both @techchizkid and @codecrafter mentioned several ways to list running services, I think there’s more to explore, especially if you’ve already used systemctl or service --status-all and need additional insights.
First off, I noticed ss was mentioned briefly but I think it deserves more attention. In many cases, it’s more effective than netstat for network-related services:
ss -tuln
This command lists all TCP and UDP sockets that are currently listening. It can be extremely useful if you’re dealing with network daemons and want to see what’s active.
If you’re running a more complex system and need a deeper dive, consider using nmap for scanning open ports and running services across your network. It’s external but powerful for a comprehensive breakdown:
sudo nmap -sT -O localhost
For those who like minimalism, instead of using the heavier htop, atop might be an alternative. atop can give you detailed insights without the extra load:
sudo apt-get install atop
atop
Unlike htop, atop logs system data, allowing historical analysis—a hidden gem when you’re troubleshooting performance issues retrospectively.
For more granular service analysis, especially if you’re dealing with user-level services, you might also want to explore these commands:
launchctl list # On macOS, for reference
While this applies to macOS, it gives an idea. For Linux, systemd-run can create transient units which are not immediately obvious in systemctl listings. Investigating transient units can reveal unexpected services:
systemctl list-units --type=service | grep transient
Sometimes, troubleshooting calls for browsing service logs detailed in journalctl. For a more specific filter:
journalctl -xe
This command focuses on the most recent logs and might pinpoint why a service isn’t running correctly.
In terms of system monitoring tools, it’s good to push boundaries. If you need a tool more tailored to your server’s specific distribution, consider distro-specific package managers and service managers. For instance, while less common, systems like Alpine Linux use openrc:
rc-status
And if exploring deeper contextual service analysis:
rc-service serviceName status
Some users overlook /proc as it’s a goldmine for direct kernel and process stats reading. For an overview of all running processes tied to network services, this might be illustrative:
cat /proc/net/tcp
This direct method can sometimes give insights missed by conventional utilities.
Lastly, understanding which services automatically start on boot can be fundamental for troubleshooting. With systemd, you can use:
systemctl list-unit-files --type=service | grep enabled
For distributions using chkconfig, as suggested, although it’s falling out of favor, comprehending runlevel scripts may be beneficial.
It’s also prudent to occasionally audit user crontabs and timers, which might silently start applications or services. The following command can list all crontabs across users:
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
With systemd timers becoming more popular, their listing and states might reveal such automated services:
systemctl list-timers
And note, many advisory services or local tools might be hiding unnecessary complexity. Staying concise with efficient commands may often yield quicker, cleaner results.
Bottom line, while systemctl and service offer robust solutions by handling init.d scripts and systemd units, exploring further into network sockets, custom automation scripts, and distribution-specific tools can supplement the troubleshooting process. Don’t get deterred by the perceived simplicity of concise tools—they often provide the fastest route to a clear, actionable insight of your running services landscape.
Try lsof for a fast snapshot of active servcies that listen on ports.
Install: sudo apt install lsof, or sudo yum install lsof.
List listeners with owners and PIDs:
sudo lsof -i -P -n | grep LISTEN
Show unique daemons:
sudo lsof -i -P -n | awk ‘/LISTEN/ {print $1}’ | sort -u
Map a PID to its full command:
ps -p PID -o pid,cmd
This covers most network daemons like sshd, nginx, postgres. It runs light in prod envrionments. If you need UDP:
sudo lsof -iUDP -P -n