I would like python3
command to exit when parent exits (after 10 seconds).
#! /bin/bash
sudo bash -c "python3 screen-buttons.py &"
sleep 10
printf "%s\n" "Done"
I would like python3
command to exit when parent exits (after 10 seconds).
#! /bin/bash
sudo bash -c "python3 screen-buttons.py &"
sleep 10
printf "%s\n" "Done"
Well, you have to know the pid you want to kill, one way or the other.
#!/bin/bash
# assuming screen-buttons.py does not output anything to stdout
pid=$(sudo bash -c 'python3 screen-buttons.py & echo $!')
sleep 10
kill "$pid"
If screen-buttons.py outputs something to stdout, save the pid to a file and read it from parent.
But it looks like you want to implement a timeout. If so see.. timeout
utility.
To kill all descendant see https://unix.stackexchange.com/questions/124127/kill-all-descendant-processes
And anyway, why call bash and background in child process? Just call what you want to call.
#!/bin/bash
sudo python3 screen-buttons.py &
pid=$!
sleep 10
sudo kill "$pid"
and anyway:
sudo timeout 10 python3 screen-buttons.py