The following outline gives a quick tour through the /proc hierarchy.
cd /proc/20/cwd; /bin/pwdNote that the pwd command is often a shell builtin, and might not work properly in this context.
cat /proc/10/environ | tr "\000" "\n"
This file is also null-terminated and not newline terminated.
[device]:inode
For example, [0301]:1502 would be inode 1502 on device major 03 (IDE, MFM, etc. drives) minor 01 (first partition on the first drive).
Also, the symbolic link can be dereferenced normally - attempting to open "exe" will open the executable. You can even type /proc/[number]/exe to run another copy of the same process as [number].
find(1) with the -inum option can be used to locate the file.
Programs that will take a filename, but will not take the standard
input, and which write to a file, but will not send their output to
standard output, can be effectively foiled this way, assuming that -i
is the flag designating an input file and -o is the flag designating
an output file:
foobar -i /proc/self/fd/0 -o /proc/self/fd/1 ...and you have a working filter. Note that this will not work for programs that seek on their files, as the files in the fd directory are not seekable.
/proc/self/fd/N is approximately the same as /dev/fd/N in some UNIX and UNIX-like systems. Most Linux MAKEDEV scripts symbolically link /dev/fd to /proc/self/fd, in fact.
The format is:
address perms offset dev inode 00000000-0002f000 r-x-- 00000400 03:03 1401 0002f000-00032000 rwx-p 0002f400 03:03 1401 00032000-0005b000 rwx-p 00000000 00:00 0 60000000-60098000 rwx-p 00000400 03:03 215 60098000-600c7000 rwx-p 00000000 00:00 0 bfffa000-c0000000 rwx-p 00000000 00:00 0
Where address is the address space in the process that it occupies, perms is a set of permissions:
r = read w = write x = execute s = shared p = private (copy on write)
offset is the offset into the file/whatever, dev is the device (major:minor), and inode is the inode on that device. 0 indicates that no inode is associated with the memory region, as the case would be with bss.
"0" is usually libc.so.4.
/proc/*/mmap was removed in Linux kernel version 1.1.40. (It really was obsolete!)
The fields, in order, with their proper scanf(3) format specifiers, are:
The total length of the file is the size of physical memory (RAM) plus 4KB.
Information in this file is retrieved with the dmesg(8) program).
It is in the same format as free(1) , except in bytes rather than KB.
IP address HW type Flags HW address 10.11.100.129 0x1 0x6 00:20:8A:00:0C:5A 10.11.100.5 0x1 0x2 00:C0:EA:00:00:4E 44.131.10.6 0x3 0x2 GW4PTSWhere 'IP address' is the IPv4 address of the machine, the 'HW type' is the hardware type of the address from RFC 826. The flags are the internal flags of the ARP structure (as defined in /usr/include/linux/if_arp.h) and the 'HW address' is the physical layer mapping for that IP address if it is known.
Inter-| Receive | Transmit face |packets errs drop fifo frame|packets errs drop fifo colls carrier lo: 0 0 0 0 0 2353 0 0 0 0 0 eth0: 644324 1 0 0 1 563770 0 0 0 581 0
sl local_address rem_address st tx_queue rx_queue tr rexmits tm->when uid 1: 01642C89:0201 0C642C89:03FF 01 00000000:00000001 01:000071BA 00000000 0 1: 00000000:0801 00000000:0000 0A 00000000:00000000 00:00000000 6F000100 0 1: 00000000:0201 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0
Num RefCount Protocol Flags Type St Path 0: 00000002 00000000 00000000 0001 03 1: 00000001 00000000 00010000 0001 01 /dev/printerWhere 'Num' is the kernel table slot number, 'RefCount' is the number of users of the socket, 'Protocol' is currently always 0, 'Flags' represent the internal kernel flags holding the status of the socket. Type is always '1' currently (Unix domain datagram sockets are not yet supported in the kernel). 'St' is the internal state of the socket and Path is the bound path (if any) of the socket.
You can also write to some of the files to reconfigure the subsystem or switch certain features on or off.
An echo 'scsi singledevice 1 0 5 0' > /proc/scsi/scsi will cause host scsi1 to scan on SCSI channel 0 for a device on ID 5 LUN 0. If there is already a device known on this address or the address is invalid an error will be returned.
Reading these files will usually show driver and host configuration, statistics etc.
Writing to these files allows different things on different hosts. For example with the latency and nolatency commands root can switch on and off command latency measurement code in the eata_dma driver. With the lockup and unlock commands root can control bus lockups simulated by the scsi_debug driver.
Linux version 1.0.9 (quinlan@phaze) #1 Sat May 14 01:51:54 EDT 1994
Last updated for Linux 1.3.11.
This manual page is incomplete, possibly inaccurate, and is the kind of thing that needs to be updated very often.