确定进程在 Linux 中是否运行,主要看进程是否在运行和端口是否被占用。
不同的操作系统的命令也会有一些不一样。
针对 Alpine 操作系统。
查看进程
查看 nginx 进程是否在运行的命令为:
ps aux | grep "[n|N]ginx"
服务器输出为:
/ # ps aux | grep "[n|N]ginx"
169 root 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
170 nginx 0:00 nginx: worker process
171 nginx 0:00 nginx: worker process
172 nginx 0:00 nginx: worker process
173 nginx 0:00 nginx: worker process
174 nginx 0:00 nginx: worker process
175 nginx 0:00 nginx: worker process
177 nginx 0:00 nginx: worker process
178 nginx 0:00 nginx: worker process
180 nginx 0:00 nginx: worker process
181 nginx 0:00 nginx: worker process
183 nginx 0:00 nginx: worker process
184 nginx 0:00 nginx: worker process
186 nginx 0:00 nginx: worker process
188 nginx 0:00 nginx: worker process
190 nginx 0:00 nginx: worker process
191 nginx 0:00 nginx: worker process
/ #
/ #
查看端口是否被占用
nginx 通常使用的是 80 端口。
所以我们可以使用下面的命令查看下 80 端口有没有被占用:
netstat -tulpn | grep :80
服务器针对上面命令的输出为:
/ # netstat -tulpn | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 169/nginx.conf
tcp 0 0 :::80 :::* LISTEN 169/nginx.conf
/ #
通过上面的方法,我们可以确定下进程有没有起来。