Peeking at the processes

Peeking at the processes

This example uses two parameters, the -e parameter, which shows all of the processes running on the system, and the -f parameter, which expands the output to show a few useful columns of information:

UID: The user responsible for launching the process
PID: The process ID of the process
PPID: The PID of the parent process (if a process is started by another process)
C: Processor utilization over the lifetime of the process
STIME: The system time when the process started
TTY: The terminal device from which the process was launched

root@dell:/etc# ps -ef |less |head -n 1
UID PID PPID C STIME TTY TIME CMD
root@dell:/etc# ps -ef |less |grep -i terminal
jyothis 3889 3271 0 08:49 ? 00:00:07 xfce4-terminal
root 4261 3996 0 09:42 pts/0 00:00:00 grep -i terminal

TIME: The cumulative CPU time required to run the process
CMD: The name of the program that was started

Using cat command to number nonempty output lines

-b, –number-nonblank
number nonempty output lines

root@dell:/etc# cat -b inittab
1 # /etc/inittab: init(8) configuration.
2 # $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $

3 # The default runlevel.
4 id:2:initdefault:

-n, –number
number all output lines

root@dell:/etc# cat -n inittab
1 # /etc/inittab: init(8) configuration.
2 # $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $
3
4 # The default runlevel.
5 id:2:initdefault:

Viewing file statistics

stat - display file or file system status

The stat command provides a complete rundown of the status of a file on the filesystem:

With no option, `stat’ reports all information about the given files. But it also can be used to report the information of the file systems the given files are located on. If the files are links, `stat’ can also give information about the files the links point to.

root@dell:~# stat hdd
File: `hdd’
Size: 384 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 1358293 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2010-01-10 17:00:07.000000000 +0530
Modify: 2009-08-01 09:08:16.000000000 +0530
Change: 2009-08-01 09:08:16.000000000 +0530

The results from the stat command show just about everything you’d want to know about the file being examined, even down the major and minor device numbers of the device where the file is being stored.


The core GNU utilities

The core GNU utilities.

The GNU project was mainly designed for Unix system administrators to have a Unix-like environment available. This focus resulted in the project porting many common Unix system command line utilities. The core bundle of utilities supplied for Linux systems is called the coreutils package.

The GNU coreutils package consists of three parts:

Utilities for handling files
Utilities for manipulating text
Utilities for managing processes

$ apt-cache search coreutils
bsdmainutils - collection of more utilities from FreeBSD
coreutils - The GNU core utilities

These three main groups of utilities each contain several utility programs that are invaluable to the Linux system administrator and programmer.

major and minor device number

Linux creates special files, called nodes, for each device on the system. All communication with the device is performed through the device node. Each node has a unique number pair that identifies it to the Linux kernel. The number pair includes a major and a minor device number. Similar devices are grouped into the same major device number. The minor device number is used to identify a specific device within the major device group. This is an example of a few device files on a Linux server:

root@dell:/dev# ls -al sda* ttyS*
brw-rw—- 1 root disk 8, 0 Feb 8 07:12 sda
brw-rw—- 1 root disk 8, 1 Feb 8 07:12 sda1
brw-rw—- 1 root disk 8, 2 Feb 8 07:12 sda2
crw-rw—- 1 root dialout 4, 64 Feb 8 07:12 ttyS0
crw-rw—- 1 root dialout 4, 65 Feb 8 07:12 ttyS1
crw-rw—- 1 root dialout 4, 66 Feb 8 07:12 ttyS2
crw-rw—- 1 root dialout 4, 67 Feb 8 07:12 ttyS3

The fifth column is the major device node number. Notice that all of the sda devices have the same major device node, 8, while all of the ttyS devices use 4. The sixth column is the minor device node number. Each device within a major number has its own unique minor device node number.

The first column indicates the permissions for the device file. The first character of the permissions indicates the type of file. Notice that the SCSI hard drive files are all marked as block (b) device, while the COM port device files are marked as character (c) devices.

« Prev - Next »