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)
}
– RuntimeException Oct 21 '22 at 16:06export -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; '
– RuntimeException Nov 05 '22 at 14:37setsid /usr/bin/flatpak run --command=de.manuel_kehl.go-for-it de.manuel_kehl.go-for-it &
– wayan Nov 19 '22 at 08:22bash -c ; disown;
thing so that it starts in another shell and the .bashrc completes successfully. But anyway, if your problem is solved, then no need to bother. – RuntimeException Nov 30 '22 at 15:12