X Window System Functionality


The X Window System, when deployed, functions as a server. Just so you know what that is, a server application (which differs from what you may be currently using as a "client") runs and provides resources for other programs and system functions.

In a Class by Itself The X Window System is an application that will provide a set of interface display functions. Other environments such as Microsoft Windows and Apple Macintosh do not.


When a client wants to make use of the X Window System display and change settings, the client will make a request to the server to make such changes.

Client/ServerSame Computer With the X Window System functioning as a server, it does not matter if the client and server are not on the same computer; they can be running separately as well as running over a computer network.


There is a lot to learn about X, and because there are so many versions, it's hard to cover all of them in one lesson. Because of this, your homework assignment is to follow this lesson as closely as you can, and after you complete it, if you want to learn more about your version of the X Window System, search www.google.com/linux and www.x.org for additional information.

Starting the X Window System

We're now ready to start X! Let's begin. Starting the X Window System is easy. To start X, you only need to type commands at the shell prompt. First, make sure you are at the shell prompt, logged in and ready to go. You may already be in the X Window System; if this is the case, close out of it and reopen it to get the experience of loading it. Please note: If you are doing this at work and unsure of what you are doing, you may want to first ask for permission from your system administrator or whoever handles the administration of your system.

If you booted up your system and it went directly into X, this means that the system has been configured to do so automatically. If it didn't, you can configure it to load automatically if you like.

To start the X Window System manually after you log in, type the following:

 >startx 

There are two primary ways to load X: either a shell script called startx (which is also known as x11 in some distributions) or the xinit program. Using startx will automate function calls to xinit, and thus is the preferred method to start X. In Lesson 14, "Shell Scripting Fundamentals," we will cover shell scripting in more depth.

Now that you know how to start the X Window System, let's talk more about it and what you need to know about starting applications.

After the X server starts itself, you will need to start some X applications as well. There is a default set available upon boot-up. A file called .xinitrc is located in your home directory. When Unix boots up, .xinitrc is automatically executed. Although this file is common, not all versions of Unix use it. Here are some examples of files used in other versions:

  • Linux distributions use ****.m4 files.

  • IRIX will use a secondary proprietary means if .xinitrc does not load initially.

The .xinitrc File Goes by Other Names Just like many other things in Unix, there are variations in the name of the .xinitrc file in different distributions. Other known versions of this file include .Xinit, .xinit, .Xinitrc, or .xsession.

Remember, Unix is case sensitive, so having upper- and lowercase letters in your commands or switches can change the meaning of the command.


So what does an .xinitrc file look like? Here's an example:

 #!/bin/sh xrdb -load $HOME/.X11defaults xscreensaver -timeout 10 & xterm -geometry 80x30+10+10 & 

An .xinitrc file, when dissected line by line, appears as follows:

  • Line 1 states to use the Bourne shell, sh.

  • Line 2 states to load the server resource database from the file .X11defaults in your home directory.

  • Line 3 states to start the command xscreensaver, assign a 10-minute timeout, and then place the process in the background.

  • Line 4 states to start an xterm (terminal), which is 80 characters wide by 30 characters high, placing it 10 pixels from the top and left of your screen.

The server resource database is discussed later in this lesson.

What's with the Ampersand? For all programs you run out of the .xinitrc file (except your controlling process), end the line with an ampersand (&). An ampersand will make sure that the program you specify is run in the background.


Now that you understand the basics of the X Window System, the xinit program, startx, and the .xinitrc file, let's tie it all together so it makes sense and so you can learn how to make configuration changes to your Unix environment. This way, you can become more comfortable while working in your Unix environment.

Tying It All Together

The xinit program is used to start the X Window System server. The first client program listed will be launched. This is launched from /etc/init. In cases in which a program is not listed, xinit will look for a file in the user's home directory. This file (shell script) is called .xinitrc. If this shell script does not exist, you can create one in your home directory that can be used.

Let's look at this file again:

 #!/bin/sh xrdb -load $HOME/.X11defaults xscreensaver -timeout 10 & xterm -geometry 80x30+10+10 & 

The first line in the .xinitrc file is used to declare the shell in which the script is written. Whatever shell you ultimately decide to use will dictate the commands you use within it. What this means is that if you use the C shell to write your script, you should be sure to use commands that are known within the C shell syntax.

In the first line of our example script, we see sh, which stands for the Bourne shell. sh is the standard Unix system command interpreter and will work for now if you use simple scripts. More complex scripting will require the use of a more complex shell, such as the C shell. sh executes commands that are either specified in a file or executed from the terminal where you sit.

In the next line of the example, you will see a personal initialization file called $HOME/.X11defaults. .X11defaults is nothing more than a profile file; that's it. You can edit your $HOME/. profile file by hand. We will learn how to do this in Part III, "File System Utilities," where we will discuss editing files in Unix.

Want to BASH Your Head into a Wall? BASH is probably the most common Unix-based shell in use. Thanks to the worldwide use of Linux, BASH users have grown to countless numbers. Most like to use BASH instead of sh because there are no history features and no aliases in sh, which can become annoying. History is important when you do not want to retype the same command 100 times a day. With BASH, simply press the up arrow on your keyboard to recall commands already used and stored in your system's memory. If you press the up arrow and all that is reported back is gibberish and unreadable commands, you may be using an older shell.


Your next step is to launch any applications you may want to use. When viewing the example .xinitrc file again, you can see that programs such as an xterm window and xscreensaver are both launched in the background. Think about what other programs you may want to start during the boot-up of your system. Helpful suggestions for what you may want to eventually add include a window manager and perhaps your e-mail client. No matter what you decide, the important thing to understand and learn here is how and where to make this change; once you know how to edit files, you can find things you want to launch and add them later.

In our example, the controlling process is the xterm window. When you close something that is designated as a controlling process, doing so will close you out of your entire X Window System session.

Let's look at another sample .xinitrc script:

 #! /bin/sh xrdb $HOME/.Xprofile xsetroot -solid gray & xclock -g 60x50-0+0 -bw 0 & xterm -g 60X24+0+0 & xterm -g 60x24+0-0 

You can see that this script is similar to the last one, and that is good. You will start to remember things such as this, and that's all it takes to learn Unix! In this sample script, you can see the power of Unix starting to open up; you can basically script anything and have it run automatically. You can even have scripts that call up other scriptsthe flexibility is endless.

To continue with our example and tie this all together, let's examine the last line of the script. The last line should be your controlling process, and when you have a controlling process, this is the one time that you do not add the ampersand.

So what does this sample .xinitrc file do? With this file, xinit will start, and your .Xprofile file will be read. Once read, your environment will start to develop. In this example, the root window will be set to solid gray. A clock will be used. Two xterm sessions (one as a controlling process) and an xconsole window will be initialized.

Start xconsole Starting an xconsole window is always recommended. This is primarily so console messages do not appear on your screen. If you don't start an xconsole, you will have to keep refreshing your screen, which can be frustrating.




    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net