Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5699890
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类:

2006-06-16 16:02:15

一个查看进程打开的文件的工具
 
 
在移植软件的时候,需要拷贝相关的动态链接库,但是有些时候仅仅拷贝了动态链
接库和相关的配置文件,还是不行。
要做到与宿主系统上的完全一致,有时strace,查看打开的文件,这样太麻烦了
 
今天,看书的时候,发现了一个系统工具lsof比较爽。
 
lsof  -c  firefox  |  awk  '{print  $9}'
 
如果是查看mplayer的话,同样;尤其是现在MPG4编码格式播放不了,但是宿主系
统上可以播放。
 
可以让宿主系统上的mplayer播放一个MPG4编码的电影,lsof一下。
 
写一个脚本来自动完成。
#!/bin/sh
#
#  This  script  will  copy  the  libraries  when  a  process  run.
#  Author:  Wangyao
#  E-mail:  wangyao@cs.hit.edu.cn
#
 
Name=$1
Store_Dir=$2
 
#Judge  the  $Store_Dir  exist  or  not
if  [  !  -z  $Store_Dir  ];then
mkdir  -p  $Store_Dir
fi
 
 
lsof  -c  $Name  |  awk  '{print  $9}'|grep  'lib'   >  lsof_lib_file
 
#  Judge  the  process  exist  or  not
if  [  !  $?  ];then
echo  "The  process  dones't  exist!"
exit
fi
 
for  file  in  $(cat  lsof_lib_file)
do
#  if  the  $Store_Dir  and  $file  have  two  //,substitute  to  /
Dir=$(echo  $Store_Dir$(dirname  $file)  |  sed  's/\/\//\//')
if  [  !  -z  $Dir  ];then
#  mkdir  $Dir  is  wrong
mkdir  -p  $Dir
fi
 
cp  -a  $file  $Dir
done


再加上以前的拷贝动态链接库的脚本,这样移植软件就比较轻松了。
阅读(2031) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~