I'm using tigthvnc server on linux machine. Often my clients are closing their vncviewrs from close button ('X'), and not exiting gracefully their sessions from OS. How can I terminate the server when they do that?
You can run VNC from your inetd daemon. RealVNC's Xvnc(1) man page has a section entitled "USAGE WITH INETD" that should help you do what you want, e.g. launch Xvnc servers on demand and kill Xvnc sessions when they are closed.
You may also want to check your specific distribution. Some Linux distros have explicit support for running VNC out of inetd. Fedora and Red Hat used to be among them, but since I no longer use either one, I'm not sure if that remains the case.
Either way, this should definitely get you pointed in the right direction.