问题描述
参考文章:nginx: [error] invalid PID number “” in “/usr/local/nginx/logs/nginx.pid”
- 编译安装完 nginx 后,启动 nginx时,出现nginx已经在运行,即nginx: [emerg] bind() to 0.0.0.0:82 failed (98: Address already in use)。然后输入
./nginx -s reload
时,出现了nginx: [error] invalid PID number “” in “/usr/local/nginx/logs/nginx.pid”的报错。 - 进程还在,没有干掉。却把进程的文件删除了,就会出现这种deleted,不正常进程。
原因分析:
卸载 nginx 前,没有关闭 nginx,导致 nginx 的内容都被删除了, nginx 的进程还保留在虚拟机中。
知识拓展:
1.如何查看nginx的进程
进程:正在运行的程序/脚本。每个进程会有对应的编号——进程号,唯一识别这个进程是谁。
1)ps -ef
- 查看系统所有进程
[root@test1 ~]# ps -ef
- 选择只看 nginx 的进程
[root@test1 ~]# ps -ef|grep nginx
nginx是多进程的程序。
2)top命令
- top命令看到的pid 进程号
[root@test1 ~]# top
- top命令后,按1:看cpu是几核的。(下图说明这个cpu是2核的。)
- 看cpu是几核的另一个命令:lscpu
[root@test1 ~]# lscpu
3)LSOF
- lsof 查看某个端口号对应的进程信息
[root@test1 ~]# lsof -i:98
2.如何查看一个进程的执行路径
- pwdx:来查看进程号(PID)对应的执行路径
[root@test1 ~]# pwdx pid
解决方法:
[root@test1 ~]# ps -ef|grep nginx
root 1486 1 0 14:15 ? 00:00:00 nginx: master process ./nginx
nobody 1487 1486 0 14:15 ? 00:00:00 nginx: worker process
root 1807 1789 0 16:06 pts/1 00:00:00 grep --color=auto nginx
[root@test1 ~]# killall -9 nginx
[root@test1 ~]# cd /usr/local/nginx/sbin/
[root@test1 sbin]# ./nginx
“kill -9 pid”:强制杀死进程。
-9:强制执行。