Wednesday, August 11, 2010

Linux X Server - Awesome Abstraction !! :-)

Before you start reading this, a headnote, this article is targetted for people familiar with linux. Though i have tried to keep it as simple as possible, some parts of this article may seem greek and latin to those who are not familiar about linux.

To start with, as the title suggests i am gonna talk about the Linux X windowing system. Before starting, there have always been so many things about linux that have been controversial (like Vi vs Emacs and Linux vs GNU/Linux to name some - people who are not familiar with all these, just ignore and read on). Linux has always been (atleast according to me) distinct in its way of organizing itself so that the users can extract maximum output of it. Adopting strictly to the basic open source principle of "choice". Briefing it in a nutshell, linux and its companions have always adhered to the goal of providing the maximum choice for its users (best example is the number of linux distributions out there (ubuntu, fedora, suse, etc)).

The linux way of architecturing a product or its feature is in such a way that it can be extracted to the fullest. I am going to write about one of the best examples of such an architecture that linux has built over years, the X Windowing System. So, what the hell is it ? If you are a linux user, you are most likely to be using the X right now. If you have seen linux before, then you have probably seen X. Before talking about the architecture of the X windowing system, let me give a brief introduction about it.

Gedit running in windows via putty

The X windowing system is the basic graphical user interface in linux. The X protocol specifies the way the windows are displayed on the screen. So whats the big deal about it? All the operating systems have some such thing that is used to display stuff on the screen. Yeah, thats true. But the way X does it is significantly different and i shall say, the designer of X is a real out-of-the-box thinker.

If you or me were designing such a system that is used to display stuff on the screen, all we would have done is make a level of abstraction over all the processes that requires display and just draw whatever is requested by the processes simply on the screen. X does just this. But how it has layered itself is what stands out.

First some terminologies. The programs which require to display something are known as the X Servers. The entity that actually interacts with the screen and draws stuff on the screen is known as the X Client. People generally tend to confuse this with the client-server model whereas this is actually client-server model with the roles reversed. In general, the guy who provides service will be called the server whereas here the guy who requests service is called server. (I still could not figure out why this terminology is followed).

The X server and client communicate via sockets. This is where X stands out. Since they communicate via sockets, yeah you guessed it right, it does not matter where the client and server runs (whether on the same machine or not). The TCP/IP stack of the OS takes care of the abstraction in how the requests and responses reach the client and server. So, the client can be any running application (even on a computer without a monitor attached to it) and the server can be any computer (of course with a monitor attached to it). As long as the client and server can communicate with each other via a network, it is possible to access both the computers using a single monitor.

Though this might sound fairly trivial today thanks to a bunch of remote GUI software available in the market, this is something that has been so well thought on those days when X was designed. It is when i see such wonderful designs i realise my college HOD's phrase "More the abstraction, Better the survival".

This article may even be a piece of junk. But i just could not resist blogging about such an awesome design.

P.S.: Seriously, you can scold me openly. :-)