首页 > 程序人生 > linux下进程名和进程id的转换

linux下进程名和进程id的转换

1.由进程名得到进程id:  pidof  xx , 其中xx是进程名

2.由进程id得到进程名: readlink /proc/xxx/exe,其中xxx是进程的id

3.如果是shell程序,因为shell的进程名是相应的shell名,所以不能直接根据shell脚本的名字来获取其进程id,可以由以下两种方法(以sh为例):

(1)通过pidof sh得到所有的sh进程的pid的集合,然后再通过ps aux|grep xxx.sh得到的进程的id,来和前面得到的id进行匹配,如果匹配到的话,就说明匹配的id是该脚本的进程id.

(2)pid=`ps gaux | grep xxx.sh | grep -v grep | awk ‘{print $2}’`

分类: 程序人生 标签: ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.

Warning: mysql_query() [function.mysql-query]: Access denied for user 'root'@'localhost' (using password: NO) in /home/wuzeshengpwmuqzeeas7h4eknug/wwwroot/wp-content/plugins/quickstats/quickstats.php on line 345

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/wuzeshengpwmuqzeeas7h4eknug/wwwroot/wp-content/plugins/quickstats/quickstats.php on line 345

Warning: mysql_query() [function.mysql-query]: Access denied for user 'root'@'localhost' (using password: NO) in /home/wuzeshengpwmuqzeeas7h4eknug/wwwroot/wp-content/plugins/quickstats/quickstats.php on line 346

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/wuzeshengpwmuqzeeas7h4eknug/wwwroot/wp-content/plugins/quickstats/quickstats.php on line 346

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/wuzeshengpwmuqzeeas7h4eknug/wwwroot/wp-content/plugins/quickstats/quickstats.php on line 346