Skip to content

Instantly share code, notes, and snippets.

@e-minguez

e-minguez/gimxstatus.py

Last active Apr 7, 2016
Embed
What would you like to do?
#!/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
You can’t perform that action at this time.