linux一些整理

脚本使用

判断进程是否存在,不存在则启动

#!/bin/bash
while [ 1 ]
do

        count=`ps -ef|grep projectname|grep -v "grep"| wc -l`
        if [ $count -le 0 ]; then
                nohup sh /root/project/bin/run.sh
                time=`date`
                outmsg="restart project"
                echo $time$outmsg >> ./restart.txt
                sleep 3
        else
                sleep 5
        fi
done

判断多进程中的僵尸进程数量

如果多进程中的僵尸进程数量到一定值,则重启主程序

#!/bin/bash
while [ 1 ]
do

		count=`ps -ef|grep projectname|grep defunct| wc -l`
        if [ $count -ge 2 ]; then
				killall -9 projectname
                sleep 2
                nohup bash /root/project/bin/run.sh
                time=`date`
                outmsg="restart Project"
                echo $time$outmsg >> ./restart.txt
                sleep 3
        else
                sleep 5
        fi
done

用top命令查询指定进程,并将结果输入到文件

#!/bin/bash
while [ 1 ]
do

        top_print=`top -n 1 -b|grep runprojectname`
        time=`date`
        space="    "
        outmsg=$time$space$top_print
        echo $outmsg>> ./topprint.txt
        sleep 5
done

一些其他命令说明

GDB调试

1.gdb 程序名称 core文件名称
2.r(运行)
3.bt (崩溃地址)

linux一些系统命令

ldd 库名称 //查看依赖库

查看gpu使用情况:watch -n 1 nvidia-smi //1秒刷新一次

top -p pid //查看指定进程的使用情况

查找文件:find . -name “*.txt” | xargs grep “content”
grep -rn “content” *

添加环境变量:
export LD_LIBRARY_PATH=/home/path:$LD_LIBRARY_PATH

压缩和解压缩文件:
tar cvf filename.tar dirpath //压缩文件
tar xvf filename.tar //解压文件

查看磁盘空间:
df -h
du -sh path/*

后台运行并将输出内容保存到文件:
nohup python3 -u file.py>log.txt 2>&1 &

tail -f filename //动态查看刷新的文件

netstat -n ip:port
netstat -t(tcp)
netstat -l(listen)

iostat -d -k 1 10 // 每1秒刷新一次,共10次,内存读写速度

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力减肥的小胖子5

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值