Archive for November, 2007

Chapter 28 (Web site builder) . Programming Environments and Interfaces 765

Friday, November 30th, 2007

Chapter 28 . Programming Environments and Interfaces 765 Figure 28-1: The Eclipse IDE. The code editor view in the center of the screen shows the code for the HelloWorld .java program. Although it isn t visible in the black-and-white figure produced for this book, the code editor performs on-the-fly syntax highlight using color and fontstyle changes. Java keywords are purple; plain comments appear in green; javadocstyle comments appear in a pale blue; strings are colored blue; and normal code is black. The right side of Eclipse displays another feature common among IDEs, a class browser. Class browsers enable developers to see the structure of their programs from the point of view of the code modules that make up the program rather than as mere files in a directory. This feature is not terribly useful for a small program such as HelloWorld.java, but larger programs that consist of dozens of classes or code modules are much easier to navigate using a code or class browser. The bottom of the screen shows various information and status windows. For example, the Problems view shows problems that might have occurred while compiling the program. Eclipse, like many other IDEs, allows you to double-click on an error in the Problems view to jump right to the error in the associated code file (see Figure 28-2).
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

764 Part VI . Programming in Linux larger (Photo web hosting)

Friday, November 30th, 2007

764 Part VI . Programming in Linux larger programs and tools that, together, perform complex tasks that no single program can do, or can do efficiently. Another element of the building blocks approach is that it enables tasks to be performed in batch mode, without active user intervention or participation. This building block philosophy is another characteristic feature of the Linux development environment, one that can make your life a lot simpler once you grok the idea. Graphical Programming Environments If you are sitting in front of a Linux system, chances are pretty good that: . It is running some version of the X Window System, . There are several xterms (terminal emulators) running on top of X s graphical interface, and . There are one or more natively graphical programs also running, such as a Web browser. Linux programming environments can be divided into two broad categories, graphical IDEs and discrete collections of command line based tools. Developers and users coming from a predominantly Windows background will be familiar with IDEs; the 800-pound gorilla in the Windows world is Microsoft s Visual Studio project. This section looks at some of the full-featured graphical IDEs that collect and merge all the constituent components necessary for the development task, such as an editor, compiler, linker, debugger, class browser, and project manager, in a single, unified interface. The examples discussed include the open source Eclipse environment, KDE environment, and Code Crusader environment. Eclipse: The Universal Tool Platform Eclipse is a large, Java-based development platform. In principle and in practice, Eclipse is a universal IDE that is used to create applications as diverse as Web sites, C, C++, and Java programs, and even plug-ins that extend Eclipse itself. Eclipse is amply capable of handling every aspect of Linux development in an astonishing variety of languages. Figure 28-1 shows Eclipse with the Hello, World example program, written in Java, on the screen. Figure 28-1 illustrates a number of characteristics typical of IDEs. The project view on the left side of the screen provides a project file browser that enables you to see at a glance the contents of the programming project. You can see the primary project folder, HelloWorld, and the some of the associated files necessary to support Java projects, such as the default package for Java projects and a folder containing the necessary JRE (Java Runtime Environment) files.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Java web server - Chapter 28 . Programming Environments and Interfaces 763

Thursday, November 29th, 2007

Chapter 28 . Programming Environments and Interfaces 763 The second rule allows you to create chains of commands, each of which uses the output of the previous command as its input. A typical use of this behavior is a command pipeline, such as the following rather contrived example: $ cat /etc/passwd | cut -f 5 -d: | tr [:lower:] [:upper:] | sort | head -5 The first part of the command pipeline, cat /etc/passwd, writes the contents of the /etc/passwd file to standard output. The second part, cut -f 5 -d:, cuts out the fifth field of its standard input (the contents of /etc/passwd), using the colon character (:) as the field delimiter (the fifth field of /etc/passwd is the GECOS or name field). The third part, tr [:lower:] [:upper:], translates all lowercase characters in the standard input to uppercase characters. The next element, sort, performs an alphabetic sort on the first letter of its input before sending the sorted list to standard output. The final component, head -5, displays only the first five lines of its standard input to standard out. The output of this pipeline might resemble: ADM BIN DAEMON GAMES LP The following command pipeline should prove more useful: it e-mails the current uptime and load average to the root user: uptime | mailx -s System Usage root The third rule, keeping programs self-contained, is related to the second. The concept behind it is that programs intended for use in command pipelines should make no assumptions about what their input might look like or do any massaging of the output. Consider the cut command shown in the first command pipeline. It takes arbitrarily formatted input and allows the user to specify on what piece of data to operate (the fifth field in the example, where fields are colon-delimited) and then just displays the requested data on standard output. cut doesn t do any post-processing of the output, allowing the user to do with it as she pleases, probably using another tool. The fourth rule is really more a philosophical observation that you can t really predict all the ways in which your program might be put to use. Indeed, as S.C. Johnson once noted, A successful [software] tool is one that was used to do something undreamed of by its author. The point is that the Linux toolkit, for both developers and end users, is full of small tools and utilities that are building block programs routinely used to create
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Web hosting bandwidth - 762 Part VI . Programming in Linux .

Thursday, November 29th, 2007

762 Part VI . Programming in Linux . Shared memory Shared memory is just what the name suggests: a region or segment of memory specifically set aside for use by multiple processes. Because shared memory is never paged out to disk, it is an extremely fast way for two processes to exchange data. . Semaphores Semaphores, briefly mentioned in the Preemptive Multitasking section, serve as flags that indicate a condition controlling the behavior of processes. For example, one process can set a semaphore to indicate a specific file is in use. Before other processes attempt to access that file, they check the semaphore s status and don t (or shouldn t) attempt to access the file if the flag is set. . Message queues Message queues are first-in-first-out (FIFO) data structures that make it possible for processes to exchange short messages in a structured, orderly manner. Message queues are not necessarily accessed in FIFO data structures. System V UNIX-style message queues are, but POSIX message queues enable readers to pull messages out of a queue in an arbitrary order. Shared memory, semaphores, and message queues are idiomatic in the Linux development environment. They solve three distinct domains of problems that arise when multiple processes need to exchange data or share resources without having to resort to slow disk files. All of which is to say that you don t always need IPC, but it sure is nice to have when you do need it. The Building Blocks Philosophy The building blocks philosophy that characterizes the Linux development is best expressed as a short series of rules or principles: . Do one thing very well. . Whenever possible, accept input data from standard input and send output data to standard output. . Keep individual programs as self-contained as possible. . Remember that someone will use your program in ways you didn t intend and for purposes that you never imagined. The first rule simply means that programs should not try to be all things to all people: a text editor doesn t need to be able to send e-mail messages and a drawing program doesn t also need to be able to function as a Web browser. Although it is less true today than it used to be, the best Linux programs don t have every imaginable feature (also known as featuritis). Rather, developers spend time perfecting the program s intended purpose and making it possible for programs to interoperate. Note
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Chapter 28 . Programming Environments and Interfaces 761 (Web design service)

Wednesday, November 28th, 2007

Chapter 28 . Programming Environments and Interfaces 761 The likelihood of deadlocks, livelocks, or races occurring increases dramatically on multitasking (and multiuser) systems because the number of processes that are potentially competing for access to a finite number of resources is greater. Good design, careful analysis, and the judicious use of locks, semaphores, and other mutual exclusion (or mutex) mechanisms, which mediate access to shared resources, can prevent or reduce their occurrence. Multiuser by Design Linux is multiuser by design, an element of the Linux development model that has far-reaching consequences for developers. A program cannot assume, for example, that it has sole access to any resource such as a file, memory, peripheral devices, or CPU time; multiple programs might be attempting to print simultaneously or trying to allocate memory. Similarly, a program cannot be written with the assumption that only one copy of the program is running at a time. So, if you are writing a program that creates temporary working files in /tmp, you need to ensure that the temporary files created by Bubba s copy of the program are distinct from the temporary files created by Mary Beth s instance of the program. If you don t, hilarity will ensue (if not hilarity, at least confusion and consternation). Another common need is for programs to honor per-user configurations. At start-up time, a program might apply reasonable global defaults and then read a user s configuration file to apply, say, a custom color scheme. There are also a number of per-user settings, such as environment variables, that programs need to know how to accommodate. For example, the $MAIL environment variable identifies where the user s mail spool file is kept and the $VISUAL environment variable defines the user s preferred full screen editor (which all true Linux users know is vi). The $PRINTER environment variable stores the name of the user s default printer and, of course, $HOME identifies the user s home directory. In a pervasively multiuser system such as Linux, programs and programmers must always take into account that most resources a program might want to use are usually shared. Likewise, they must also take into account that most real-world usage scenarios (more formally known as use cases) assume that multiple instances of the program are running at the same time. Interprocess Communication Interprocess communication (IPC) enables programs to share data and resources with a minimum amount of overhead and is used extensively on all Linux systems. It is especially common with daemons and server process that spawn child processes to handle client connections. IPC comes in three varieties: shared memory, semaphores, and message queues:
Check Tomcat Web Hosting services for best quality webspace to host your web application.

760 Part VI . Programming in (X web hosting) Linux program,

Wednesday, November 28th, 2007

760 Part VI . Programming in Linux program, then preempts it (interrupts or suspends it) to spend another 50 millisecond quantum executing another program. It then preempts the second program to execute the third, and so on until the scheduler returns to your program, when (under normal circumstances) the round robin starts again. The context switch between programs happens so rapidly that you have the illusion that your program is running all the time. Task preemption happens automatically and unavoidably; very few processes escape preemption. What you might not realize, however, is that a process can voluntarily yield its quantum of CPU time. That is, while a process cannot request additional CPU time, it can voluntarily give it up. The implication of this for a developer is that you can delay executing certain blocks of code if they are either noncritical or rely on input from other processes that are still running. The function that makes this possible is named sched_yield(). Multitasking, while a boon for computer users, poses (at least) three potential problems for programmers: deadlocks, livelocks, and races. . Deadlocks A deadlock occurs when two or more processes are unable to proceed because each is waiting for one of the others to do something. Deadlocks can happen in several ways. For example, suppose an e-mail client is communicating with a mail server, waiting on the server to send a message. A deadlock occurs if the mail server is waiting for input from the e-mail client before sending the message. This type of deadlock is sometimes referred to as a deadly embrace. A starvation deadlock occurs when one or more low-priority processes never get time on the CPU because they are crowded out by higherpriority processes. A third common type of deadlock occurs when two processes are trying to send data to each other but can t because each process s input buffers are full because they are so busy trying to send data that they never read any data sent by the other process. This type of deadlock is colorfully referred to as constipation. . Livelocks A livelock occurs when a task or process, usually a server process, is unable to finish because its clients continue to create more work for it to do before the server can clear its queue. The difference between a livelock and a deadlock is that a deadlocked process doesn t have any work queued; it is blocked or waiting for something to happen. A livelocked process, on the other hand, has too much work to do and never empties its work queue. . Races A race occurs when the result of a computation depends on the order in which two events occur. Say, for example, that two processes are accessing a file. The first process writes data to the file and the second process reads data from the file to calculate and display a summary value. If the reader process reads the file after the writer completes, the reader calculates and returns the correct value. If the reader process reads the file before the writer completes, the reader will calculate and return an incorrect summary value.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Chapter 28 (Graphic web design) . Programming Environments and Interfaces 759

Tuesday, November 27th, 2007

Chapter 28 . Programming Environments and Interfaces 759 The Security Model As you learned earlier in this book, all users are not created equal. Some users, such as the root user, are effectively omnipotent and can do anything on a system. Most users have more limited access. The user (and group) IDs of these less privileged users control what programs they can execute and the files they can access. The same restrictions apply to the development environment. For example, if you write a program, you might not be able to access a certain feature, such as locking memory with the mmap() system call, unless your program runs with root permissions. If your program creates files, the default file permissions are controlled by the umask of the user executing the program and/or a umask that you might specifically set at runtime using the umask() system call. Naturally, your program cannot create, delete, or modify files or directories if it doesn t have the necessary privileges. The Linux development environment also makes it possible for a program to drop or add privileges at runtime by calling functions that change its UID or GID. The impact of the Linux security model on programming is two-fold. First, the same rules and restrictions that affect running programs and other elements of normal system usage also affect the process of creating programs and what those programs can do. This effect is no more than the logical consequence of the Linux security model itself. Programmatically, however, you have more ways, or perhaps more finely grained ways, to interact with the security subsystem than you do as a normal user of the system. The second effect of the Linux security model for programmers is that writing a program imposes significant burdens on programmers to program securely. An e-mail program, for example, that stores usernames and passwords in a text file that is unencrypted and/or world-readable is just as insecure as a program that fails to check user input for buffer overflow. To use a subtler example, when faced with a problem that seems to require root privileges, such as access to a sound card, the initial impulse is usually to run the program as root. However, there are often user space solutions that can accomplish the same goal and that do not require root access. In the case of writing programs that access a sound card, for example, the ALSA (Advanced Linux Sound Architecture) libraries give application programmers access to a rich interface for emitting squeaks and squawks without needing to rely on running a program as the root user. Preemptive Multitasking Perhaps the easiest way to express the preemptive multitasking characteristic of programming in a Linux environment is simply to write, You don t own the CPU; it only seems like you do. In imprecise terms, the CPU (actually, the CPU scheduler, which is part of the kernel) allocates a quantum of time (on the order of 50 milliseconds) to execute your
You want to have a cheap webhost for your apache application, then check apache web hosting services.

758 Part VI . (Web server on xp) Programming in Linux programs,

Tuesday, November 27th, 2007

758 Part VI . Programming in Linux programs, such as Web browsers, e-mail clients, graphics programs, and games run outside of kernel mode in what is colloquially referred to as user space. The distinction between kernel space and user space is important. The kernel has raw, uncontrolled access to system resources such as the CPU, RAM, and attached peripherals. The kernel mediates all access from user space programs to system resources, funneling it through the system call, or syscall, interface. The syscall interface carefully checks the data passed in from user programs before passing that data on to other parts of the kernel. As a result of this careful gatekeeping, it is extremely rare for even the most poorly written user space program to crash the kernel. The strict division between kernel and user space code is what contributes to Linux reliability and stability and why you hardly ever see the familiar Windows Blue Screen of Death on a Linux system (except in a screensaver). In addition to the distinction between kernel and user mode code, the kernel and user programs also have their own distinct memory regions. Each process, each instance of a running program, has a virtual memory space, known more formally as the process address space, of 4GB. Under most circumstances, the kernel gets 1GB of this space, while user space gets the other 3GB. User space programs are not permitted to access kernel memory directly. As with CPU and peripheral protection, the motivation for strict memory partitioning is to prevent ill-behaved (or even deliberately malicious) programs from modifying kernel data structures, which can create system instability or even crash the system. The distinction between kernel and user space is another fundamental feature of the Linux development environment that gives developers considerable flexibility to write almost any code they want with reasonable assurance that if their program crashes, it won t also crash the system. At the same time, the syscall interface that serves as the gateway between user mode and kernel mode code enables user mode programs to access kernel features and services in a safe, controlled manner. Moreover, the kernel can perform tasks that ordinarily might be executed by user space programs without needing a different programming model. For example, if you implement some sort of user space functionality, such as providing a basic HTTP server, in the kernel, the same syscall interface makes it possible to interact with the HTTP server; there is no need to use a new or different programming interface. On the downside, the sharp delineation between kernel and user space creates some disadvantages for normal users. For example, unlike Microsoft Windows, user space programs do not have direct access to hardware devices. For user space programs to access a sound card, for example, the system administrator must take steps to permit this sort of access. However, this is a small inconvenience compared to the increased stability for which Linux systems are known.
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Chapter 28 . Programming Environments and Interfaces 757 (Web design software)

Monday, November 26th, 2007

Chapter 28 . Programming Environments and Interfaces 757 execl( /bin/ls , /bin/ls , NULL); } else { printf( in parentn ); waitpid(child, &status, 0); } return 0; } Don t worry about what all the code means. The key points to understand are: . The child - fork() statement creates a new (child) process. . The code between if (child — 0) and the else statements is executed in the child process. In particular, the child uses the execl() function call to execute the /bin/ls program, which creates a directory listing of the current directory. . The waitpid() statement is executed in the parent process, which means that the parent process will wait for the child process to terminate before continuing execution. You can compile this program with the following command (if you have the GCC compiler installed): $ gcc forkexec.c -o forkexec And then execute it like this: $ ./forkexec in parent in child 28.doc a.out forkexec forkexec.c Your output might be slightly different. The point to take away from this example is that Linux makes it very easy to create new processes programmatically. Because it is so easy, it is a common and powerful programming technique and a characteristic of the Linux programming model. Linux is hardly alone in providing a mechanism by which one program can start another, but the fork()/exec() technique is unique to Linux (and the UNIX systems on which it is based). CPU and Memory Protection Another fundamental component of programming on Linux systems is that the operating system itself, which consists of the Linux kernel, is almost entirely insulated from all application programs. The kernel runs in a protected CPU mode known variously as ring 0, kernel mode, or, more prosaically, kernel space. User
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

756 Part (Web hosting control panel) VI . Programming in Linux .

Monday, November 26th, 2007

756 Part VI . Programming in Linux . Preemptive multitasking . Its multiuser design . Interprocess communication . The building blocks approach Let s take a closer look at each of these features. The Process Model The process model is the way that Linux creates and manages running processes. Provided that a process has the necessary privileges, it can create (or spawn) other processes, referred to as child processes. The parent process can also exchange data with child processes. Of course, the capability to create child processes is not unique to Linux, but the particular way in which Linux does so is characteristic of all UNIX-like systems. When a process calls the fork() system call, it creates an exact copy of itself. After being created by the fork() call, the child process typically calls one of a family of functions collectively known as exec(), providing a program to execute and any options or arguments to that program. Listing 28-1 illustrates the fork()/exec() process. Actually, the child process created when a process fork()s, isn t an exact duplicate of the parent. The process ID (PID) of the child process is different, as is the parent PID (PPID); any file locks held by the parent are reset, and any signals pending for the parent are cleared in the child. Listing 28-1: Simple fork() and exec() Sequence /* * forkexec.c - illustrate simple fork/exec usage */ #include #include #include #include int main(int argc, char *argv[]) { pid_t child; int status; child = fork(); if (child == 0) { printf( in childn ); Note
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.