1

I ran a R console on our server, and the process took much longer time than I expected. Thus I was trying close it by ctrl+z, it didn't work. Finally I just closed the terminal. But the process is still there when I check with top commands. I used kill, but won't kill the process. The top command output:

 PID   USER     PR   NI  VIRT    RES    SHR  S  %CPU %MEM  TIME+ COMMAND     
27448 zhenyang  20   0 20.133g 0.020t 3.840g R 100.0 21.3  72:00.06 R 

I checked the website and someone says it might be ctrl+z put the process in background, but fg command won't work.

Anyone help?

  • To kill it: kill 27448. To kill it with fire (i.e. this has unwanted side effects, so try it only if the first version doesn't work): kill -9 27448. – Satō Katsura Sep 05 '16 at 07:23
  • @SatoKatsura, I have tried both, and both won't work. something weird is that "20.133g 0.020t 3.840g", although I don't quite understand the meaning, they are different from other processes. – concer guo Sep 05 '16 at 07:34
  • Is it a process from your user? If you don't care killing every single one of your processes, do the big kill -9 -1 – J. Chomel Sep 05 '16 at 07:38
  • There's obviously a defunc process at play here. – Julie Pelletier Sep 05 '16 at 07:52
  • @J.Chomel, I tried and it works, and I checked before I use the big kill. Thanks! – concer guo Sep 05 '16 at 07:56
  • @JuliePelletier, I was afraid using kill -9 -l that I might do something wrong. But It works. As I am not the administrator of the server, and there currently is no process running from my own, except the one I mentioned, so I give it a try. It works. I should be more carefully in future about this! – concer guo Sep 05 '16 at 07:57
  • BTW, killing process -1 is a very bad idea. If the system lets it pass, it will crash the machine, probably rebooting it. Your sysadmin may not be very happy since it won't do a clean shut down if it works. – Julie Pelletier Sep 05 '16 at 08:24
  • 1
    @JuliePelletier Passing -1 as the process ID kills all the processes of the calling user (of any user if the calling user is root) except init. This is standard behavior. A non-root user cannot crash the machine. – Gilles 'SO- stop being evil' Sep 05 '16 at 22:50
  • 1
    @J.Chomel Given that the intent is to kill a specific process, there is absolutely no reason to kill all processes with -1. – Gilles 'SO- stop being evil' Sep 05 '16 at 22:50
  • @Gilles: I've tried, as a regular user, kill(-1) on old versions of SunOS and Digital and in those two systems it crashed the system. – Julie Pelletier Sep 05 '16 at 23:00
  • @JuliePelletier, you mean you launched kill -9 -1 with root user? Yes of course, it kills every single process owned by the user... But sometimes it doesn't work... I'm not very accurate on the topic, so I avoided posting it as an answer. It seems to have work for the OP though. – J. Chomel Sep 06 '16 at 06:18
  • @J.Chomel: As I said, it was done with a non-priviledged user. Note that it didn't work on the command line, just in a C program. It was most likely a bug in the C library but we didn't dig into it - just did the test as we'd heard of the possible issue. – Julie Pelletier Sep 06 '16 at 06:20

2 Answers2

3

Run the command kill and pass it the process ID, i.e. in your case

kill 27448

By default, this kills the process, but if the program has set up a signal handler, it may continue to run. If the process keeps running, use

kill -KILL 27448

(or equivalently kill -9 27448). The KILL signal cannot be caught, it always kills the process. (Maybe not immediately if the process is doing some long input/output, but it does kill it.)

0

CTRL+Z does not kill processes, it suspends their execution (aka it stops them). It does this by sending the TSTP signal to the process which can be resumed by sending the CONT signal to the process.

kill -CONT <pid>

Once suspended the processes won't respond to other nice signals like TERM (which is what kill sends by default) until the process is resumed with the CONT signal - at which point it will process all pending signals immediately. The exception to this is the KILL signal which immediately kills the process without giving it a chance to end gracefully.

kill -KILL <pid>

This is generally discouraged as it will skip any teardown/cleanup the process normally does. Instead of CTRL+Z you should use CTRL+C to ask the foreground process to end. This sends the INT signal to the process which generally (not always) has similar behaviour to the TERM signal - it asks the process to end gracefully.

You can read more about linux/bash process job control here.