Linux 如何检查特定服务是否在 Ubuntu 上运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18721149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:48:15  来源:igfitidea点击:

How to check if a particular service is running on Ubuntu

linuxpostgresqlserviceubuntu-12.04

提问by abcd

I do not know the service's name, but would like to stop the service by checking its status.

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

For example, if I want to check if the PostgreSQLservice is running or not, but I don't know the service's name, then how could I check its status?

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

I know the command to check the status if the service name is known.

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

采纳答案by Radu

I don't have an Ubuntu box, but on Red Hat Linuxyou can see all running services by running the following command:

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

service --status-all

On the list the +indicates the service is running, -indicates service is not running, ?indicates the service state cannot be determined.

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

回答by Mike Makuch

Maybe what you want is the ps command;

也许你想要的是 ps 命令;

ps -ef

will show you all processes running. Then if you have an idea of what you're looking for use grep to filter;

将显示所有正在运行的进程。然后,如果您知道要查找的内容,请使用 grep 进行过滤;

ps -ef | grep postgres

回答by linuxnewbee

If you run the following command you will get a list of services:

如果您运行以下命令,您将获得服务列表:

sudo service --status-all

To get a list of upstart jobs run this command:

要获取新贵工作的列表,请运行以下命令:

sudo initctl list

回答by zhecsan

For Ubuntu (checked with 12.04)

对于 Ubuntu(使用 12.04 检查)

You can get list of all services and select by color one of them with 'grep':

您可以获得所有服务的列表,并使用“grep”按颜色选择其中之一:

sudo service --status-all | grep postgres

Or you may use another way if you know correct name of service:

或者,如果您知道正确的服务名称,您可以使用另一种方式:

sudo service postgresql status

回答by Amey Jadiye

You can use the below command to check the list of all services.

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

ps aux 

To check your own service:

要检查您自己的服务:

ps aux | grep postgres

回答by Satish

Dirty way to find running services. (sometime it is not accurate because some custom script doesn't have |status| option)

查找正在运行的服务的肮脏方式。(有时它不准确,因为某些自定义脚本没有 |status| 选项)

[root@server ~]# for qw in `ls /etc/init.d/*`; do  $qw status | grep -i running; done
auditd (pid  1089) is running...
crond (pid  1296) is running...
fail2ban-server (pid  1309) is running...
httpd (pid  7895) is running...
messagebus (pid  1145) is running...
mysqld (pid  1994) is running...
master (pid  1272) is running...
radiusd (pid  1712) is running...
redis-server (pid  1133) is running...
rsyslogd (pid  1109) is running...
openssh-daemon (pid  7040) is running...

回答by Angel

There is a simple way to verify if a service is running

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

systemctl status service_name

Try PostgreSQL:

试试 PostgreSQL:

systemctl status postgresql

回答by BattleTested

the best way is using of nmaptool in terminal. nmap is an useful tool that analyse an up system, using it's IP Address, then show all actived network services.

最好的方法是nmap在终端中使用工具。nmap 是一个有用的工具,可以分析 up 系统,使用它IP Address,然后显示所有活动的网络services

open terminaland use of this example :

打开terminal和使用这个例子:

~$ nmap 192.168.1.3/24

Starting Nmap 5.21 ( http://nmap.org ) at 2016-05-16 22:49 IRDT
Nmap scan report for 192.168.1.3
Host is up (0.00020s latency).
Not shown: 994 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
23/tcp   open  telnet
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
3389/tcp open  ms-term-serv
3689/tcp open  rendezvous

回答by Walk

For centos, below command worked for me (:

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

locate postgres | grep service

Output:

输出:

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

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

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

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

sudo systemctl status postgresql-9.3.service

回答by Inder malviya

run

ps -ef | grepname-related-to-process

ps -ef | grep名称相关的进程

above command will give all the details like pid, start time about the process.

上面的命令将提供所有详细信息,例如 pid、有关进程的启动时间。

like if you want all java realted process give java or if you have name of process place the name

就像如果你想要所有的 java realted 进程给 java 或者如果你有进程的名称放置名称