More about /proc directory

17 06 2008

One of the most interesting directories on any Linux system is /proc, a virtual filesystem that provides a plethora of information on the hardware of the running system, and of the various processes running. In fact, many programs such as ps and top obtain their information by mining /proc.

Some well-known virtual files in /proc include /proc/cpuinfo, which prints out information on the running CPU(s); /proc/meminfo, which prints out information on installed memory; and /proc/cmdline, which provides the arguments to the Linux kernel at boot.

Other lesser-known files in /proc include:

  • /proc/apm, which provides information related to Advanced Power Management, if installed
  • /proc/loadavg shows the system load average
  • /proc/filesystems shows the available filesystem support in the kernel and whether or not they are in use on a block device
  • /proc/mounts will show what mounts are currently active, what block device they belong to, where they are mounted, and what options were used to mount them
  • /proc/net directory contains more files, all related to network information

Most of these files look like text files so can be looked at using the cat utility, such as:

# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 15
model           : 47
model name      : AMD Athlon(tm) 64 Processor 3500+
stepping        : 2
cpu MHz         : 2202.909
...

Further, if you look inside /proc, you will notice quite a few numbered directories. These numbers correspond to running processes. Inside each directory are a number of files that give information regarding the process. For instance, /proc/1/ would contain information on process #1, which is typically init.

Some files in this directory are symlinks; the /proc/1/cwd symlink points to /, which indicates that init’s current working directory is /, the root directory. The /proc/1/exe symlink points to /sbin/init, the program that is running. The /proc/1/cmdline is a file containing the command-line used to execute the program. The /proc/1/status file indicates the status of the program, which can be used to determine if a program is sleeping or a zombie process, the amount of memory it’s using, the number of threads, the user/group privileges it is running as, and more.

To determine what files are in use by a process, look in the /proc/[pid]/fd/ directory. Each link in the directory will point to a file that is in use by the process in question.

There is a lot of information in /proc that can be found by those willing to look. A number of front-ends exist to help parse the information — tools like ps, top, and free, among many others provide more human-readable information, but to really find out what a program is doing, the authoritative resource is the /proc directory.





How to mount ssh directories using FuSe

17 06 2008

Traditional methods for uploading, downloading, or editing remote files predominantly have consisted of using an FTP client. An FTP client works fine for uploading and downloading, but editing remote files is a chore, as you have to download a file, edit it, then upload it again. And privacy with FTP is an issue as well.

More recently, other methods have become available, such as FTP with TLS support to protect authentication credentials, and the use of SFTP and SCP to copy files with encryption. While these solved the privacy issues, the convenience factor remained absent; you still needed to download a file, edit it, then re-upload it.

Using protocols like DAV allowed for the use of sharing files via HTTP or HTTPS, and some FTP clients made editing remote files more transparent — removing the manual steps. Even then, navigating remote file systems was limited to the interface of the FTP or DAV client.

The FUSE project has made editing remote files convenient by allowing local-filesystem-like access to remote files. With plugins like sshfs, which transparently makes an SFTP connection to a remote system seem like nothing more than a local directory, convenience and privacy are both available.

Most Linux distributions today provide FUSE support and also provide the sshfs plugin, so it should be a simple matter to install. Some distributions limit access to FUSE, which can be a wise thing considering how powerful it is. Distributions like Mandriva require that users who are allowed to use FUSE are added to the fuse group, which can be accomplished by executing, as root:

# usermod -G fuse joe

This will add the user joe to the fuse group, granting him permission to use FUSE. When this is done, mounting a remote directory that you normally have access to via ssh or SFTP is a simple matter of executing, as the user:

$ sshfs host:/path ~/localpath

This mounts the directory /path on the remote host host in the directory ~/localpath on the local system. Executing the mount command now, it is plain that the remote directory is mounted:

$ mount
host:/path on /home/joe/localpath type fuse.sshfs (rw,nosuid,nodev,max_read=65536,user=joe)

Navigating to ~/localpath will enter the remote file system, and from here you can use any local tool to manipulate files as you wish. You can copy files using cp, navigate the directory tree using Konqueror, and edit files with vim or OpenOffice.org, etc.

To unmount this directory, use the fusermount command:

$ fusermount -u ~/localpath

The sshfs command can also take a number of extra arguments, such as the -p argument to connect to a port other than the standard port 22. Adding sshfs to /etc/fstab can also allow for persistent remote directory sharing using FUSE and sshfs, instead of other connection methods such as NFS. By default, the FUSE mounts are unique to a single calling user, but with options such as -o allow_root or -o allow_other, you can permit access to the mounts to root and/or other users respectively.

FUSE is a very powerful system, and sshfs is just one plugin that can be used with it. FUSE modules exist to provide read/write access to NTFS partitions, navigating archive files without expanding them first, navigating relational databases as if they were regular file systems, encrypted file systems, and more. More information on FUSE and the various plugins available for it can be found at http://fuse.sourceforge.net/.