在ubuntu的bash中循環執行腳本,並在內存不足時重啓

#!/bin/bash
date
ma=`grep MemAvailable /proc/meminfo | awk '{print $2}'`
echo MemAvailable = $ma

runningloop=0

while true
do

  ((runningloop=runningloop+1))

  termname="darknet-running-${runningloop}"

  gnome-terminal -t $termname -- bash -c "bash ./darknet.sh"

  ma=`grep MemAvailable /proc/meminfo | awk '{print $2}'`
  ((ma=ma/1000))
  echo MemAvailable = $ma MB

  while [ $ma -gt 2000 ]
  do
    date
    ma=`grep MemAvailable /proc/meminfo | awk '{print $2}'`
    ((ma=ma/1000))
    echo MemAvailable = $ma MB
    sleep 1s
  done
  

  pkill darknet
  sleep 5s

done
相關文章
相關標籤/搜索