Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I run the following command in my remote linux box that I connect to from my windows 7 laptop via VNC I get the following :

 [subhrcho@slc04lyo ~]$ ps -ef|grep vnc
subhrcho 20113 19804  0 21:40 pts/8    00:00:00 grep vnc
subhrcho 27486     1  0 Jan28 ?        00:05:35 Xvnc :1 -desktop slc04lyo:1 (subhrcho) -httpd /usr/share/vnc/classes -auth /home/subhrcho/.Xauthority -geometry 1680x1050 -depth 16 -rfbwait 30000 -rfbauth /home/subhrcho/.vnc/passwd -rfbport 5901 -pn
subhrcho 27493     1  0 Jan28 ?        00:00:00 vncconfig -iconic

How can I kill this session elegantly ? I know kill -9 <pid> would do it but I think that is a forceful clean and might lead to corrupted files .

P.S: I also read from this source to use the kill option from vncserver but not sure how to figure out display#.

share|improve this question

As you noticed, from the man vncserver:

  -kill :display#
          This kills a VNC desktop previously started with vncserver. It does
          this by killing the Xvnc process, whose process ID is stored in the
          file "$HOME/.vnc/host:display#.pid". It actually ignores anything
          preceding a ":" in its argument. This can be useful so you can write
          "vncserver -kill $DISPLAY", for example at the end of your xstartup
          file after a particular application exits.

The display number is connected to the port number of the display if one hasn't set that manually (and differently), where

Display number = (Port number) ‒ 5900

e.g. port 5901 → display :1. This information can be found in man Xvnc (vncserver is just a wrapper script that calls this tool) where it says:

   -rfbport port
          Specifies the TCP port on which Xvnc listens for connections from
          viewers (the protocol used in VNC is called RFB - "remote
          framebuffer").  The default is 5900 plus the display number.

If you don't know the number by heart (but you need to know it if you are going to connect to the server anyway), you can check e.g. ps ax | grep vnc for information. If I do that locally, I see the processes

25697 ?        S     55:38 Xvnc4 :1 [...]
[...]
30481 ?        S     17:57 Xvnc4 :2 [...]

and thus I know that they represent VNC servers with display numbers :1 and :2 respectively, and can be killed by

vncserver -kill :1
vncserver -kill :2

In your case, you see that the display number is :1 for the server listed in your ps output.

share|improve this answer

I tried the answer above and it didn't work for me. It gave me an error message as in this question: Killing VNC Process Manually

So I had to kill them manually. I tried kill -9, and then I couldn't log in with rdp anymore. I got xrdp_mm_process_login_response: login failed when I tried to log in.

The answer was found here: http://linuxtoolkit.blogspot.com/2013/03/xrdpmmprocessloginresponse-login-failed.html

Basically, there is a session file not cleaned up when the Xvnc server is killed. The file is named for the display, so if you're on display :12, it's /tmp/.X11-unix/X12. Delete that file after kill -9 and you're back in business.

share|improve this answer
    
Script I wrote to auto-kill idle sessions: gist.github.com/mnebuerquo/e825530cf2bfd363b6c3cd82fe697d94 – Mnebuerquo yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.