Last active
April 7, 2016 18:34
-
-
Save e-minguez/66bcddc971fb9305079d318c7d387fec to your computer and use it in GitHub Desktop.
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
#!/bin/python | |
import os | |
import time | |
import RPi.GPIO as GPIO | |
# set GPIO pin 7 as output | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(7, GPIO.OUT) | |
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
def Shutdown(channel): | |
os.system("sudo shutdown -h now") | |
GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000) | |
while True: | |
found = False | |
time.sleep(5) | |
pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] | |
for pid in pids: | |
try: | |
cmd = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read() | |
if "gimx" in cmd: | |
found = True | |
except IOError: # proc has already terminated | |
continue | |
if found == True: | |
GPIO.output(7, True) | |
else | |
GPIO.output(7, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment