alp-ch07-proc-filesystem

alp-ch07-proc-filesystem - 09 0430 CH07 5/22/01 10:30 AM...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The /proc File System 7 T RY INVOKING THE mount COMMAND WITHOUT ARGUMENTS —this displays the file systems currently mounted on your GNU/Linux computer.You’ll see one line that looks like this: none on /proc type proc (rw) This is the special /proc file system . Notice that the first field, none , indicates that this file system isn’t associated with a hardware device such as a disk drive. Instead, /proc is a window into the running Linux kernel. Files in the /proc file system don’t corre- spond to actual files on a physical device. Instead, they are magic objects that behave like files but provide access to parameters, data structures, and statistics in the kernel. The “contents” of these files are not always fixed blocks of data, as ordinary file con- tents are. Instead, they are generated on the fly by the Linux kernel when you read from the file.You can also change the configuration of the running kernel by writing to certain files in the /proc file system. Let’s look at an example: % ls -l /proc/version -r--r--r-- 1 root root 0 Jan 17 18:09 /proc/version Note that the file size is zero; because the file’s contents are generated by the kernel, the concept of file size is not applicable.Also, if you try this command yourself, you’ll notice that the modification time on the file is the current time.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
148 Chapter 7 The /proc File System What’s in this file? The contents of /proc/version consist of a string describing the Linux kernel version number. It contains the version information that would be obtained by the uname system call, described in Chapter 8,“Linux System Calls,” in Section 8.15,“ uname ,” plus additional information such as the version of the compiler that was used to compile the kernel.You can read from /proc/version like you would any other file. For instance, an easy way to display its contents is with the cat command. % cat /proc/version Linux version 2.2.14-5.0 (root@porky.devel.redhat.com) (gcc version egcs-2.91. 66 19990314/Linux (egcs-1.1.2 release)) #1 Tue Mar 7 21:07:39 EST 2000 The various entries in the /proc file system are described extensively in the proc man page (Section 5).To view it, invoke this command: % man 5 proc In this chapter, we’ll describe some of the features of the /proc file system that are most likely to be useful to application programmers, and we’ll give examples of using them. Some of the features of /proc are handy for debugging, too. If you’re interested in exactly how /proc works, take a look at the source code in the Linux kernel sources, under /usr/src/linux/fs/proc/ . 7.1 Extracting Information from /proc Most of the entries in /proc provide information formatted to be readable by humans, but the formats are simple enough to be easily parsed. For example, /proc/cpuinfo contains information about the system CPU (or CPUs, for a multiprocessor machine). The output is a table of values, one per line, with a description of the value and a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

alp-ch07-proc-filesystem - 09 0430 CH07 5/22/01 10:30 AM...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online