This repository provides two python codes:
- memory_monitor.py
Check computer's memory usage periodically and notify user when memory is almostly run off. - kill.py
After finding the abnormal processes which take a lot of memory, this code can kill all processes with the same program name.
- Step 1: Make a sender.list and a receiver.list.
Apply a new gmail account with some [permission configuration](https://support.google.com/accounts/answer/185833).
Fill in the sender.list and receiver.list as given sample.
[sender.list](sender.list) includes sender email account and password.
[receiver.list](receiver.list) includes number of users and eamil addresses of users.
- Step 2: Run memory_monitor.py at background.
- There are two parameters to adjust in [memory_monitor.py](memory_monitor.py). 1. mem_threshold: If free memory below to this value( in MB), the monitor would notify the user. 2. detect_interval: Period of the detect time( in sec).
- There are a lot of ways to run code in background, and you can use your own method.
For example,
this command would run the code in background and output the log to mem.log file.
nohup python3 -u memory_monitor.py > mem.log &
- Step 3: If receiving a mail, check out what happened. If abnormal detected, you will get mail like: And then, tou can use tools like htop to figure out what happened.
- Step 4: If there is a large number of processes, use kill.py to kill them all.
If you found somthing like this:
Use kill.py to kill all processes.
sudo python3 kill.py <program_name>
This tool is something like toy comparing to other mature programs. Maybe simple and buggy but easy to use. Any problem may happen when you use it :).