Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108379
  • 博文数量: 24
  • 博客积分: 3020
  • 博客等级: 中校
  • 技术积分: 205
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-23 16:24
文章分类
文章存档

2010年(1)

2008年(23)

我的朋友

分类: LINUX

2008-05-28 18:08:50

Another way to locate a particular process is by what the process is accessing. The
fuser command can be used to find which processes have a file or a socket open at
the moment. After the processes are found, fuser can be used to send signals to those processes.

The fuser command is most useful for finding out if files are being held open
by processes on mounted file systems (such as local hard disks or Samba shares).
Finding those processes allows you to close them properly (or just kill them if you
must) so the file system can be unmounted cleanly.

Here are some examples of the fuser command for listing processes that have files open on a selected file system:

# fuser -mauv /boot          Verbose output of processes with /boot open
USER PID ACCESS COMMAND
/boot/grub/: root 3853 ..c.. (root)bash
root 19760 ..c.. (root)bash
root 28171 F.c.. (root)vi
root 29252 ..c.. (root)man
root 29255 ..c.. (root)sh
root 29396 F.c.. (root)vi

The example just shown displays the process ID for running processes associated with /boot. They may have a file open, a shell open, or be a child process of a shell with the current directory in /boot. Specifically in this example, there are two bash shells open in the /boot file system, two vi commands with files open in /boot, and a man command running in /boot. The -a shows all processes, -u indicates which user owns each process, and -v produces verbose output.

Here are other examples using fuser to show processes with files open:

# fuser /boot              Show parent PIDs for processes opening /boot
/boot: 19760c 29396c

# fuser -m /boot           Show all PIDs for processes opening /boot
/boot: 3853c 19760c 28171c 29396c 29252c 29255c

# fuser -u /boot           Show PIDs/user for this shell open in /boot
/boot: 19760c(root) 29396c(root) 29252c(root) 29255c(root)

After you know which processes have files open, you can close those processes manually or kill them. Close processes manually if at all possible, because simply killing processes can leave files in an unclean state! Here are examples of using fuser to kill or send other signals to all processes with files open to a file system:

# fuser -k /boot           Kill all processes with /boot files open (SIGKILL)
# fuser -l                 List supported signals

HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO
PWR SYS UNUSED
# fuser -k -HUP /boot Send HUP signal to all processes with /boot open
 
 
-摘自《Wiley SUSE Linux Toolbox 1000 plus Commands for openSUSE and SUSE Linux Enterprise》
阅读(1100) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~