How to get the process ID to kill a nohup process?

2020-01-25 03:22发布

I'm running a nohup process on the server. When I try to kill it my putty console closes instead.

this is how I try to find the process ID:

ps -ef |grep nohup 

this is the command to kill

 kill -9 1787 787

10条回答
太酷不给撩
2楼-- · 2020-01-25 03:38

when you create a job in nohup it will tell you the process ID !

nohup sh test.sh &

the output will show you the process ID like

25013

you can kill it then :

kill 25013
查看更多
戒情不戒烟
3楼-- · 2020-01-25 03:39

I am using red hat linux on a VPS server (and via SSH - putty), for me the following worked:

First, you list all the running processes:

ps -ef

Then in the first column you find your user name; I found it the following three times:

  • One was the SSH connection
  • The second was an FTP connection
  • The last one was the nohup process

Then in the second column you can find the PID of the nohup process and you only type:

kill PID 

(replacing the PID with the nohup process's PID of course)

And that is it!

I hope this answer will be useful for someone I'm also very new to bash and SSH, but found 95% of the knowledge I need here :)

查看更多
戒情不戒烟
4楼-- · 2020-01-25 03:39

suppose i am running ruby script in the background with below command

nohup ruby script.rb &

then i can get the pid of above background process by specifying command name. In my case command is ruby.

ps -ef | grep ruby

output

ubuntu   25938 25742  0 05:16 pts/0    00:00:00 ruby test.rb

Now you can easily kill the process by using kill command

kill 25938
查看更多
劫难
5楼-- · 2020-01-25 03:53

I started django server with the following command.

nohup manage.py runserver <localhost:port>

This works on CentOS:

:~ ns$netstat -ntlp
:~ ns$kill -9 PID 
查看更多
登录 后发表回答