Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

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.