fdisk

硬盘容量及分区大小的算法;

我们通过fdsik -l 可以发现如下的信息:

Disk /dev/sda: 73.5 GB, 73543163904 bytes

255 heads, 63 sectors/track, 8941 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14         535     4192965   82  Linux swap

/dev/sda3             536        8941    67521195   83  Linux

其中 heads 是磁盘面;sectors 是扇区;cylinders 是柱面;每个扇区大小是

512byte,也就是0.5M

通过上面的例子,我们发现此硬盘有 255个磁盘面,有63个扇区,有8941个柱

面;所以整个硬盘体积换算公式应该是:

磁面个数 x 扇区个数 x 每个扇区的大小512 x 柱面个数 = 硬盘体积 (单位

bytes)

5.4 磁盘管理类命令-fdisk

fdisk 分区管理

[root@node1 ~]#  fdisk /dev/sdb

Command (m for help): m

Command action

a   toggle a read only flag

b   edit bsd disklabel

c   toggle the mountable flag

d   delete a partition

l   list known partition types

m   print this menu

n   add a new partition

o   create a new empty  DOS partition table 

p   print the partition table

q   quit without saving changes

s   create a new empty Sun disklabel

t   change a partition's system id

u   change display/entry units

v   verify the partition table

w   write table t o disk and exit

x   extra functiona lity (experts only)

Command (m for help):

5.4 磁盘管理类命令-fdisk

[root@node1 ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 8941.

There is nothing wrong  with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs  at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 73.5 GB, 73543163904 bytes

255 heads, 63 sectors/ track, 8941 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *            1          13      104391   83  Linux

/dev/sda2               14         535     4192965   82  Linux swap

/dev/sda3              536        8941    67521195   83  Linux

Command (m for help):

[root@node1 ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 8941.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n

Command action

e   extended

p   primary partition (1-4)

输入P

若分区仅作一个,则默认enter

Command (m for help):w

5.4 磁盘管理类命令-fdisk

第六章:Linux操作系统的进程管理

6.1 程序和进程

程序是为了完成某种任务而设计的软件,比如OpenOffice是程

序。什么是进程呢?进程就是运行中的程序。

一个运行着的程序,可能有多个进程。 比如WWW服务器是

apache服务器,当管理员启动服务后,可能会有好多人来访

问,也就是说许多用户来同时请求httpd服务,apache服务器

将会创建有多个httpd进程来对其进行服务。

6.1.1 进程分类

进程一般分为交互进程、批处理进程和守护进程三类。

值得一提的是守护进程总是活跃的,一般是后台运行,守护

进程一般是由系统在开机时通过脚本自动激活启动或超级管

理用户root来启动。比如在FedoraRedhat中,我们可以定

httpd 服务器的启动脚本的运行级别,此文件位于

/etc/init.d目录下,文件名是httpd/etc/init.d/httpd

就是httpd服务器的守护程序,当把它的运行级别设置为35

时,当系统启动时,它会跟着启动。

[root@localhost ~]# chkconfig --level 35 httpd on

由于守护进程是一直运行着的,所以它所处的状态是等待请

求处理任务。比如,是不是访问网站,网站的httpd服务器都

在运行,等待着用户来访问,也就是等待着任务处理。

6.1.2 进程的属性

进程IDPID):是唯一的数值,用来区分进

程;

子进程和父进程的IDPPID)

启动进程的用户IDUID)和所归属的组

GID);

进程状态:状态分为运行R、休眠S、僵尸Z

进程执行的优先级;

进程所连接的终端名;

进程资源占用:比如占用资源大小(内存、

CPU占用量)。

6.1.3 父进程和子进程

他们的关系是管理和被管理的关系,当父进程终止

时,子进程也随之而终止。但子进程终止,父进程

并不一定终止。比如httpd服务器运行时,我们可以

杀掉其子进程,父进程并不会因为子进程的终止而

终止。

在进程管理中,当我们发现占用资源过多,或无法

控制的进程时,应该杀死它,以保护系统的稳定安

全运行;

6.2 进程管理

对于Linux进程的管理,是通过进程管理工具实现

的,比如pskillpgrep等工具

6.2.1 ps 监视进程工具

ps 的参数说明;

获得线程信息:

ps -eLf

ps axms

获得进程树:

ps -ejH

ps axjf

l 长格式输出;

u 按用户名和启动时间的顺序来显示进程;

j 用任务格式来显示进程;

f 用树形格式来显示进程;

a 显示所有用户的所有进程(包括其它用户);

x 显示无控制终端的进程;

r 显示运行中的进程;

6.2.1 ps aux lax输出的解释

USER 进程的属主;

PID 进程的ID

PPID 父进程的ID

%CPU 进程占用的CPU百分比;

%MEM 占用内存的百分比;

NI 进程的NICE值,数值大,表示较少占用CPU时间;

VSZ 进程虚拟大小;

RSS 驻留中页的数量;

TTY 终端ID

WCHAN 正在等待的进程资源;

START 启动进程的时间;

TIME 进程消耗CPU的时间;

COMMAND 命令的名称和参数;

6.2.1 ps aux显示的进程状态

STAT 进程状态

D Uninterruptible sleep (usually IO)

R 正在运行可中在队列中可过行的;

S 处于休眠状态;

T 停止或被追踪;

W 进入内存交换(从内核2.6开始无效);

X 死掉的进程(从来没见过);

Z 僵尸进程;

< 优先级高的进程

N 优先级较低的进程

L 有些页被锁进内存;

s 进程的领导者(在它之下有子进程);

l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do) 

+ 位于后台的进程组;

WCHAN 正在等待的进程资源; START 启动进程的时间; TIME 进程消耗

CPU的时间; COMMAND 命令的名称和参数。

6.2.2 pgrep

pgrep 是通过程序的名字来查询进程的工具,一般是

用来判断程序是否正在运行。在服务器的配置和管理

中,这个工具常被应用,简单明了

6.2.2 pgrep 用法

#pgrep 参数选项 程序名

常用参数

-l 列出程序名和进程ID

-o 进程起始的ID

-n 进程终止的ID

举例:

[root@localhost ~]# pgrep -l httpd

4557 httpd

4560 httpd

4561 httpd