Chapter 28 . Programming Environments and Interfaces 757 (Web design online)
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.