本文主要是工作中常用的linux 进程相关的命令:
- system 内存查看入free -h ,版本查看 lsb_release -a,linux/32、64查看, timestamp to datetime
- lsof根据端口查杀进程
- 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 -t
This version converts to gigabytes:(以GB方式查看内存)
awk '$3=="kB"{$2=$2/1024**2;$3="GB";} 1' /proc/meminfo | column -t
For 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 datetime
date -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 脚本