I am trying to interface my homemade Raspberry Pi-powered arcade machine with a coin acceptor, and for that I:
- use a shell script (named gameplay) which starts the game emulator (MAME) when a coin is inserted
- (want to) kill the MAME process(s) when the time is up (decided by an Arduino interface connected to the RPi), and go back to the loop in the shell script to (sleep and) wait for coin again
all is well except that I can't seem to kill the MAME process.
Please see the photo for more details. The first pstree shows the processes when a game is being played. And the second pstree is when time is up, and the "emulationstation" process has been killed by the gameplay shell script (by sudo killall emulationstation).
But the "mame" process is still there and the game can still be played. I have also tried "sudo killall mame" but it doesn't work.
I've been trying many ways but none works so far.
UPDATE AFTER SOME OF YOUR KIND COMMENTS
I found that all the processes in the branch can be killed, except for the "mame" process, no matter what I tried. The best killall effort always results in "mame" becoming a sub-branch of "init" as: "init--mame---5*[{mame}]". Running "sudo killall mame" here gives nothing - no error, no effect. Why can't I just kill this process? (and this is a process of the "pi" user).
Then I tried a more violent kill, as @Colin Ameigh suggested below: "killall -9 mame" after the "killall emulationstation". And it ALMOST works, only that something was screwed up in the "gameplay" script - the terminal becomes blank, and the INSERT COIN... text is no longer there (but except for this, it works as intended, I also don't remember noticing any zombie processes). Here is the content of the gameplay script:
while true
do
clear
echo INSERT COIN...
while [[ $(cat /sys/class/gpio/gpio4/value) == '0' ]]; do
sleep 1
done
echo STARTING GAME...
#start game as separate process
emulationstation &
while [[ $(cat /sys/class/gpio/gpio4/value) == '1' ]]; do
sleep 1
done
sudo killall emulationstation
#sudo killall mame
sudo killall -9 mame
done