G
G
Gleb Prudinsky2019-08-21 16:52:19
Electronics
Gleb Prudinsky, 2019-08-21 16:52:19

How to run a bash script on button press and terminate on release?

There is a task:
- We pressed and hold the button connected via the Raspberry pi 3+ GPIO comb - The
script started
- The button was released
- The script was forced to stop
Googling did not help, I found only the launch of the script
How can this be implemented? Generally. not necessarily bash, you can python. php

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2019-08-21
@CooLeroff

on click, run the script in the background, in the script write its PID
to the file, kill it on release
kill $(cat myscript.pid)

V
vanyamba-electronics, 2019-08-21
@vanyamba-electronics

You can stop and continue the execution of a process in Linux using the kill function .
Here is an example in Python.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question