Created
June 21, 2018 12:07
-
-
Save keysona/289feea0ed2bc57cd63b4ef6cd307ecf to your computer and use it in GitHub Desktop.
Mac free memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 需要用root用户来安装crontab任务 | |
| # $ sudo su - | |
| # # crontab -e | |
| # 复制这个: */1 * * * * /Users/keysona/OneDrive/bin/free_mem.sh | |
| # */1 代表每分钟执行一次脚本 | |
| limit=500 # 小于500MB,自动清理内存 | |
| mem=$(top -l 1 | head -n 10 | grep PhysMem | cut -f6 -d ' ' | cut -f1 -d 'M') | |
| if [ $mem -lt $limit ] | |
| then | |
| echo time to free mem! | |
| bash -c "purge" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment