I've always successfuly used an ampersand to start an application in the background from within a script. Such background applications seem to be detached from the script that started it, meaning that when I terminate the script, the applications keep running.
I now have a script that first starts a number of applications, some of them flatpaks, and then starts an endless while loop to monitor my ip address to check that the vpn is still working.
#!/bin/bash
start application 1 &
start application 2 &
start flatpak application 1 &
start flatpak application 2 &
while true
do
check ip address
sleep 180
done
When I terminate the script with ctrl-C, the non-flatpak applications keep running (as expected), but the flatpaks are terminated.
This, however, only happens if the script has this while loop: if I remove the while loop, then all applications keep running when I terminate the script, including the flatpaks.
So far, I've tried:
- calling the applications with the ampersand:
/usr/bin/flatpak run --command=de.manuel_kehl.go-for-it de.manuel_kehl.go-for-it &
- calling the applications with nohup:
nohup /usr/bin/flatpak run --command=de.manuel_kehl.go-for-it de.manuel_kehl.go-for-it &
- calling disown after starting the application
/usr/bin/flatpak run --command=de.manuel_kehl.go-for-it de.manuel_kehl.go-for-it &
disown
None of these approaches help.
Can someone explain why this happens? And is there a solution? I would like to keep all applications, including the flatpaks, running when I terminate the script.
tnx
(using bash on Linux Mint 19.3 MATE)
function runapp() { if [ $1 == "geany" ]; then echo file to open [$2]; /usr/bin/flatpak run --command=geany --file-forwarding org.geany.Geany @@ $2 @@ 1>~/logs/geany.out 2>~/logs/geany.out &; disown; return 0; fi }export -f run; declare -f run;bash -c '/usr/bin/flatpak run --command=de.manuel_kehl.go-for-it de.manuel_kehl.go-for-it &; disown; '