Forked (using single ampersand) Flatpak process dies if I close the terminal I launched it from

Hi,

I am completely new to flatpak.

I installed the flatpak for Telegram Desktop from Telegram Desktop | Flathub.

Then I typed “Telegram” into the Application launcher, and an item called Telegram Desktop (with the Telegram icon) showed up, so I clicked it, but that showed this error:

image

So, I launched it from a terminal instead, with:

flatpak run org.telegram.desktop &

Note the & at the end. Usually, that means that I can close the terminal and the program I launched keeps running, but not in this case. If I close the terminal, Telegram closes too.

Why is that? Is there a workaround?

Also, any idea why the launcher doesn’t work in the first place? EDIT: that part I figured out, I needed to reboot (no, log out and in is not enough)

How exactly did you do the install?

Have you tried logigng out and in again?

Binaries are available in /var/lib/flatpak/exports/bin, which is automatically added to $PATH by /etc/profile.d/flatpak-bindir.sh. You may have to re-login to apply the change.

https://wiki.archlinux.org/title/Flatpak

Please edit your topic title to be clear and concise about the issue. The current title is a partial phrase and doesn’t really make much sense.

Please see:

Anyway, you already have an upstream issue regarding it:

I just fixed the topic title on behalf of the OP to make it more understandable.

Is it better with the quotes around the “&”?

EDIT: someone else has further edited it. My original title was “Flatpak dies if I close the terminal I launched it from, even with &”; I guess what confused you was the lack of quotes around the “&”, other than that it made perfect sense.

No, that’s a completely different issue, it has nothing to do. It’s funny that you went through all the trouble to google some of the things I mentioned, but did not even read my post.

No. Is the edit @scotty65 made alright?

Oh, sorry. I was focused on something else. All my brain saw was your username and Flatpak together. :laughing: I’ve edited my earlier post accordingly.

Who did what now? :thinking: I neither used a search engine for anything here nor there.

That wasn’t enough. Reboot did fix the issue. Having to log out and in wouldn’t be an acceptable requirement either. Is that a bug in Flatpak or somewhere in KDE?

I dont use flatpak, but at the already linked ArchWiki page it seems to be expected behavior.

https://wiki.archlinux.org/title/Flatpak#Run_applications

Instead of roundabout and tedious things, like seen here:

The /etc/profile.d/flatpak-bindir.sh script updates your PATH for you … but may need to be reinitialized.

Maybe you could run it yourself or do something or other without having to go through poweroff etc. But again, I dont use flatpak, and the docs seem to expect it to act this way.

I’m still curious about the original question: why closing the terminal closes the flatpak app even if the command launching it was executed with the “&” at the end.

Because putting an ampersand behind the command only daemonizes it — i.e. it is being executed as a background job of your shell, and the shell supports multitasking, so the process can still be brought back to the foreground.

Whether running in the foreground or the background, the parent process is still the shell itself, and if you close the terminal window, then you’re killing the parent process.

You probably want to use nohup instead.

1 Like

Whether running in the foreground or the background, the parent process is still the shell itself, and if you close the terminal window, then you’re killing the parent process.

How come it works with most other programs, though?

I don’t know. FlatPaks are not normal programs — they run in isolated containers — so perhaps it’s got something to do with that :man_shrugging:

No, it doesn’t. Everything will close with terminal.
You need to run either

disown # after 'some_command &'
# or 
nohup some_command &

Oops, I guess @Aragorn already answered that.

1 Like

Interestingly, not everything. For whatever reason, it works with Kate, which is what I quickly tried before posting here. But it seems to be the exception rather than the rule.

Now I’m curious why it works with Kate specifically. Maybe it does something special on startup?

:man_shrugging: I guess it disowns itself or whatever.