Archive for November, 2007

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

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.
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 (Web server) Interfaces 763

Wednesday, November 28th, 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
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

762 Part VI . Programming in (Web hosting support) Linux .

Tuesday, November 27th, 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
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Chapter 28 (Php web hosting) . Programming Environments and Interfaces 761

Monday, November 26th, 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:
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Php web hosting - 760 Part VI . Programming in Linux program,

Sunday, November 25th, 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.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Chapter 28 . Programming Environments and Interfaces 759 (Mac os x web server)

Friday, November 23rd, 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
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

758 Part VI . Programming in Linux programs, (Web design course)

Thursday, November 22nd, 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.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

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

Tuesday, November 20th, 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
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Apache web server for windows - 756 Part VI . Programming in Linux .

Monday, November 19th, 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
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Web hosting - Chapter 28 . Programming Environments and Interfaces 755

Sunday, November 18th, 2007

Chapter 28 . Programming Environments and Interfaces 755 As you will discover, some of the graphical IDEs provide comfortable editors for writing code, drawing dialog boxes, and navigating the file system, but use the command-line tools to do the work of compiling the code, hiding the command-line tools beneath an attractive interface. The Linux Development Environment The Linux development environment consists of the services and capabilities provided by the kernel and core system components. These services and capabilities both define and limit how to write programs that run on a Linux system. Consider files and the file system. Linux, like the UNIX systems on which it is modeled, is built on the key idiom that everything is file. This is a powerful metaphor and model that dramatically simplifies writing application programs to communicate with all sorts of devices. How? You can use the same function, the write() system call, to write data to a text file; to send data to a printer; to send keystrokes to an application; and, if you had one, to tell your network-connected coffee pot to brew another pot of coffee. The file metaphor works this way because Linux treats all devices, such as modems, monitors, CD-ROM drives, disc drives, keyboards, mice, and printers as if they were files. Device drivers, which are part of the kernel, sit between a device and the user and application trying to access it. A device driver translates an application s write() call into a form that the device can understand. So, if an application uses the write() system call to write data to a text file on an ext3 file system, the ext3 driver writes the necessary bytes to a file on the disk, but if the application later uses the write() system call to write that same data to a printer, the printer driver transmits that data out the parallel port (or across the network) to the printer in a manner that the printer can understand and interpret. This is one way in which the Linux development environment informs, or defines, writing programs on a Linux system. The catch? If the device you want to use doesn t have a driver, you can t use the write() call to do anything with that device. You simply do not have a way to communicate with the device. This is how the Linux development environment constrains programming on a Linux system. What, then, in addition to the file idiom already discussed, are the key features of Linux that characterize its development environment? In no particular order: . The process model . CPU and memory protection . The security model
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.