How can I auto end a specific process when it reaches 400 MB RAM? And how do I change it back after I do that ? Is there any program or script or anything ?!
1 Answer
Here goes the sample script:
#!/bin/bash
# Here put the name of your process
ProcName="process_name"
# Here put the desired memory limit in KBytes
MemLimit=400000
ProcID=$(pidof "$ProcName")
if [ -z "$ProcID" ] ; then echo "Process not found" ; exit ; fi
while true
do
MemCurrent=$(grep VmSize /proc/"$ProcID"/status | cut -f 2 | tr -d ' kB')
if [ $MemCurrent -gt $MemLimit ]
then
kill -9 "$ProcID"
exit
fi
sleep 5
done
Set your desired process name and memory limit in ProcName
and MemLimit
variables. Save this script somewhere, for example as ~/killer.sh
. Make it executable: chmod +x killer.sh
. Then run it: ./killer.sh
.
What do you mean by "change it back"?
N.B. Actually VmSize
will not give you exact memory usage. Calculation of real process memory usage is a complex task. You can get some insight here: https://stackoverflow.com/questions/131303. But I think that this script will be sufficient in your case.
-
where can i put dat script i wrote them on wordpad file and change its ex 2 bat but it was ineffective– STABOct 14, 2013 at 23:19
-
There is no
wordpad
in Ubuntu (at least in default installation). Wordpad and batch files are from the Windows world. Do you meangedit
instead? I added some more instructions to make the things more clear. As for the script - it works. I tested it. As soon as the process exceeds itsVmSize
limit, it is closed promptly.– whtygerOct 15, 2013 at 11:43 -
hello sorry for disturb would u upload dat script file 2 media fire or what ever and gme da link for process name "Sro_Client.exe" on limit "400kb" and iwana know if that script works for windows 7 ultimate 64 bit– STABOct 22, 2013 at 21:38
-
It seems to me that you are looking for solution in completely wrong place. You are asking questions at askUBUNTU forum (hint: all questions here are UBUNTU related). Go and seek somewhere at askWINDOWS forums. I'm done.– whtygerOct 23, 2013 at 7:37