Notice! This document is currently in Archived status.
The content of this document may be incorrect or outdated.

Print this article Edit this article

The xinitrc file?

Purdue Engineering Computer Network


The xinit program is used to start the X Window System server and a first client program on systems that cannot start X directly from /etc/init or in environments that use multiple window systems.

If no specific client program is given on the command line, xinit will look for a file in the user's home directory called .xinitrc to run as a shell script to start up client programs.

If you are not using the generic .xinitrc dot file .xinitrc start-up script, then you need to create one in your home directory.

The first line of the startup script should list the shell that it's written in. For simple scripts the Bourne shell (sh) should suffice. The first line in your startup script should be:

	#! /bin/sh

Whatever shell you decide to use, the commands you insert in this startup script should be written in that shell's syntax. So, for example, if your script is written in C shell, the commands you insert should be written in C shell syntax.

Think about what programs you want to start. One program you have to start a window manager. You probably want to start at least one xterm window. You may want to start a mailer or a calendar program. Start out with a few programs, you can always add more later.

The next thing you need to decide is which program you want to be your controlling process. The controlling process is a program that, when you exit it, you are out of your entire X session. There are two common programs to use as your controlling process: your window manager or an xterm window.

In the start-up script, twm is the controlling process. So, when you exit twm, you exit your X session.

Now list all your programs on separate lines. For all programs except your controlling process, end the line with an ampersand (&)so the program is run in the background. This way you can have windows from several client programs running simultaneously.

The last line should be your controlling process for which you do not add an ampersand. For example, below is the generic .xinitrc:

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

Examining the above script, we see that upon starting xinit, your .Xdefaults file will be read, your root window will be set to solid gray, a clock, two xterms and an xconsole window will be started. Starting an xconsole window is recommended so you do not have console messages appear on your screen. If you don't start an xconsole, you will have to keep refreshing your screen. The last line is your twm window manager which is run as your controlling process. Therefore when you exit your window manager (by selecting Exit from the Twm menu), your X Window system will shut down and you will be returned to your console prompt.

Placing Your Windows

After you have your initial startup session, you may want to set up inital window placements. You can set your window placement with the -geometry (-g).

Setting Your Geometry

The geometry of a window consists of its dimensions and its position on the screen.

The client has a default size built into the program, and the placement of the window is usually controlled by the window manager. The window manager might be set up to place clients randomly, stacked on top of one another, or require the user to manually place each new window. However, you can override the client defaults and window manager placement using the -geometry (-g) command-line option.

For example, looking at the .xinitrc, the xclock line appears with a geometry of 60x50-0+0 -bw &. The dimensions are 60x50. The coordinates (-0,+0) represent the upper right corner of the root window. The numbers following the plus signs (+) signify the horizontal and vertical offset (in number of pixels) from (0,0). So if you specify +0+0, there's no offset and your window appears at the upper left corner. If you specify -0+0 your window appears at the upper right corner.

The easiest way to configure your window size is by trial and error. Try the dimensions above, if you dont' like them, edit your .xinitrc file and start X again. Or you can use the xwininfo command.

After you have created/edited this file, save the file as .xinitrc and chmod it 755 (chmod 755 .xinitrc). Then logout of your workstation and log back in again.

To start X Windows using your .xinitrc script, at your workstation prompt (console prompt) type:

	xinit

Last Modified: Dec 19, 2016 11:12 am US/Eastern
Created: May 31, 2007 1:36 pm GMT-4 by admin
JumpURL: