Created
November 5, 2012 09:10
-
-
Save jroesch/4016194 to your computer and use it in GitHub Desktop.
For when Chrome gets cranky and takes all your memory ...
This file contains 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
module SleepyTime where | |
-- Check out System.Proccess to avoid using the tmp file. | |
import System.Cmd | |
import System.Exit (ExitCode(..)) | |
-- Find something lighter weight for the filtering. | |
import Text.Regex.TDFA | |
main :: IO () | |
main = do | |
exit <- system "ps -eaxo pid,command | grep '/Applications/Google Chrome\\.app.* --type=renderer.*' | grep -o '^ [0-9]*' > /tmp/result.sleepy_time" | |
contents <- case exit of | |
ExitFailure _ -> error "Well... your fucked this didn't work at all good luck with kill." | |
ExitSuccess -> readFile "/tmp/result.sleepy_time" | |
let pids = map eatWhiteSpace $ filter (=~ "[0-9]+") $ lines contents | |
exit' <- rawSystem "kill" $ ["-9"] ++ pids | |
case exit' of | |
ExitFailure _ -> error "So ... you passed the first round, but this did not work at all." | |
ExitSuccess -> putStrLn "Chrome went nighty night." | |
eatWhiteSpace :: String -> String | |
eatWhiteSpace xs = filter (\x -> x /= ' ' && x /= '\t') xs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment