linux进程常用命令

来源:互联网 发布:新生入学调查问卷知乎 编辑:程序博客网 时间:2024/05/20 00:49

本文主要是工作中常用的linux 进程相关的命令:

  1. system 内存查看入free -h ,版本查看 lsb_release -a,linux/32、64查看, timestamp to datetime
  2. lsof根据端口查杀进程
  3. nohup xargs ps,top 常用 (查看指定用户的进程,进程kill)

sys 相关


lsb_release -a
uname -a for all information regarding the kernel version,
cat /proc/meminfo

This will convert any kB lines to MB:(以MB方式查看内存)awk '$3=="kB"{$2=$2/1024;$3="MB"} 1' /proc/meminfo | column -tThis version converts to gigabytes:(以GB方式查看内存)awk '$3=="kB"{$2=$2/1024**2;$3="GB";} 1' /proc/meminfo | column -tFor completeness, this will convert to MB or GB as appropriate:(以MB/GB方式查看内存)awk '$3=="kB"{if ($2>1024**2){$2=$2/1024**2;$3="GB";} else if ($2>1024){$2=$2/1024;$3="MB";}

下面示例

这里写图片描述

这里写图片描述
这里写图片描述

这里写图片描述

将timestamp 显示为具体时间(无需跑代码直接command查看)

timestamp to datetimedate -d @1278999698 +'%Y-%m-%d %H:%M:%S' Where the number behind @ is is the number in seconds  

这里写图片描述

lsof根据端口查杀进程


一般thrift中使用的比较多根据端口号,杀掉进程

    sudo lsof -t -i:9001        sudo kill $(sudo lsof -t -i:9001)  //kill the process    fuser -n tcp -k 9001                  //kill the process

xargs ps,top 常用 (查看指定用户的进程,进程kill)


nohub run process background(nohub 当我们在终端比如SecureCRT中执行python demo.py当当前会话结束的时候程序也会退出
为了使得程序不退出一般使用 nohub )

nohub (run process as a background process)eg1.    nohup ./yourscript &eg2.    nohup python main.py &  

ps top查看指定user的进程
ps -f -u username
top -u username
这里写图片描述

这里写图片描述

一般在shell脚本中比如我们重新发包,会首先把原来的进程kill掉,在run新的进程一般 ps -ef | grep processname| grep -v grep
下面的更简洁点:
ps -ef| grep ‘[p]rocessname’

这里写图片描述

一般kill 掉所有进程

 ps -ef | grep "$1" | awk '{print $2}' | xargs kill -9

具体可以见另一篇bolg监控进程并重启进程的shell 脚本

原创粉丝点击