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
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
When using
nohup
and you put the task in the background, the background operator (&
) will give you the PID at the command prompt. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, viakill PID
orkill -9 PID
(if you need to force kill). Alternatively, you can find the PID later on byps -ef | grep "command name"
and locate the PID from there. Note thatnohup
keyword/command itself does not appear in theps
output for the command in question.If you used a script, you could do something like:
This will run
my_command
saving all output intomy.log
(in a script,$!
represents the PID of the last process executed). The2
is the file descriptor for standard error (stderr
) and2>&1
tells the shell to route standard error output to the standard output (file descriptor1
). It requires&1
so that the shell knows it's a file descriptor in that context instead of just a file named1
. The2>&1
is needed to capture any error messages that normally are written to standard error into ourmy.log
file (which is coming from standard output). See I/O Redirection for more details on handling I/O redirection with the shell.If the command sends output on a regular basis, you can check the output occasionally with
tail my.log
, or if you want to follow it "live" you can usetail -f my.log
. Finally, if you need to kill the process, you can do it via:Suppose you are executing a java program with nohup you can get java process id by
output
then you can kill the process by typing
or lets say that you need to kill all the java processes then just use
this command kills all the java processors. you can use this with process. just give the process name at the end of the command
You could try
jobs -l should give you the pid for the list of nohup processes. kill (-9) them gently. ;)
This works in
Ubuntu
Type this to find out the
PID
All the running process regarding to java will be shown
In my case is
Now kill it
kill -9 3315
The zombie process finally stopped.
Today I met the same problem. And since it was a long time ago, I totally forgot which command I used and when. I tried three methods:
ps -ef
command. This shows the time you start your process, and it's very likely that you nohup you command just before you close ssh(depends on you) . Unfortunately I don't think the latest command is the command I run using nohup, so this doesn't work for me.ps -ef
command. It means Parent Process ID, the ID of process that creates the process. The ppid is 1 in ubuntu for process that using nohup to run. Then you can useps --ppid "1"
to get the list, and check TIME(the total CPU time your process use) or CMD to find the process's PID.lsof -i:port
if the process occupy some ports, and you will get the command. Then just like the answer above, useps -ef | grep command
and you will get the PID.Once you find the PID of the process, then can use
kill pid
to terminal the process.