Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1872481
  • 博文数量: 283
  • 博客积分: 10141
  • 博客等级: 上将
  • 技术积分: 2931
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-21 14:33
文章分类

全部博文(283)

文章存档

2013年(2)

2012年(2)

2011年(17)

2010年(36)

2009年(17)

2008年(18)

2007年(66)

2006年(105)

2005年(20)

分类:

2007-07-04 22:43:26

Publisher: Prentice Hall PTR

Pub Date: October 14, 2005

ISBN: 0-13-149247-0

Pages: 456

 

Date: 2007-07-04

Chpt.5. System Information (/proc)

> What is proc?

The /proc file system isn’t a real file system on hard disk. It’s a reflection of the system in the memory and an interface to the kernel. Many tools such as vmstat, ps, iostat and so on get information from the /proc file system. Also you can modify some parameters of the running kernel from the /proc file system.

>  Mapping of /proc

I wrote a tool to read some parts of the /proc file system. I skipped this section. It is no use to write down the entries of each file here. But remember, the /proc of Linux is much better than Solaris.

 

Chpt.6. System Tools

>   Processes

The maximum number of processes/threads can be created in a system is limited by memory. It is set up in /usr/src/linux-2.6.x/kernel/fork.c in fork_init().

max_threads = mempages / (THREAD_SIZE/PAGE_SIZE) / 8;

You can modify this number on-the-fly by the /proc file system like this:

# echo xxx > /proc/sys/kernel/threads-max

>    Task States

Processes are managed by the kernel in this structure-- task_struct, which is defined in the /usr/src/linux-2.6.x/include/linux/sched.h. In this file, also six task states are defined:

TASK_RUNNING -- The process is in the run queue(Maybe running or waiting to be executed.)

TASK_INTERRUPTIBLE -- The process is suspended, waiting for a signal or resource.

TASK_UNINTERRUPTIBLE -- The process is waiting for a resource. It is in the same "wait queue" as the TASK_INTERRUPTIBLE state, except that delivering a signal to the sleeping process leaves its state unchanged. This process state is seldom used. However, it is valuable under certain specific conditions in which a process must wait until a given event occurs without being interrupted.

TASK_STOPPED -- The process is being debugged.

TASK_ZOMBIE -- The process child is without a parent. Process execution is terminated, but the parent process has not yet issued a wait().

TASK_DEAD -- The process is dying.

> Tools for Working with Processes

Four useful commands: ps, pgrep, pstree, top.

E.g. To show the system calls currently being executed: ps -eo pid,%cpu,vsz,args,wchan

>  strace Traces System Calls

The commond "strace" can get system calls(args, return value) + signals. For example,

#strace -o output "command"

or the output will be written to stderr without the option -o.

If you think it is a system call fails in your application, strace should be very useful.

> The Magic Key Sequence Gets a Back Trace

Visit for more information.

If your Linux system is hanging but your keyboard is still functioning, these steps perform a back trace of the current running process and all processes using the magic key sequence:

1. The kernel that is running on the system must be built with CONFIG_MAGIC_SYS-REQ enabled. Do the following operations in text mode.

2. Press Alt-ScrollLock followed by Ctrl-ScrollLock. These magic keystrokes give you a stack trace of the currently running processes and all processes, respectively.

3. Look in the system's /var/log/messages file for the back trace. If everything is set up correctly, the system should have converted the symbolic kernel addresses.

lsof Lists Open Files -- list open files

>  Network Debugging Tools

# ifconfig

# arp

# tcpdump

# netstat –an / -tap

ethereal (A GUI tool)

阅读(1375) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~