我不知道服务的名称,但想通过检查其状态来停止服务。

例如,如果我想检查PostgreSQL服务是否正在运行,但我不知道服务的名称,那么我该如何检查它的状态?

如果知道服务名,我知道检查状态的命令。


当前回答

基于类似主题的回答https://askubuntu.com/a/58406我更喜欢:/etc/init.d / postgres状态

其他回答

有一种简单的方法可以验证服务是否正在运行

systemctl status service_name

试试PostgreSQL:

systemctl status postgresql

您可以使用以下命令查看所有服务的列表。

ps aux 

检查您自己的服务:

ps aux | grep postgres

我没有Ubuntu的盒子,但在Red Hat Linux上,你可以通过运行以下命令查看所有正在运行的服务:

service --status-all

列表中的“+”表示服务正在运行,“-”表示服务未运行,?表示无法确定服务状态。

基于类似主题的回答https://askubuntu.com/a/58406我更喜欢:/etc/init.d / postgres状态

对于centos,下面的命令对我有用(:

locate postgres | grep service

输出:

/usr/lib/firewalld/services/postgresql.xml

/usr/lib/systemd/system/postgresql-9.3.service

sudo systemctl status postgresql-9.3.service