RetroFed Forums
Your home away from modern life.
Delegate a process to a file, for later reattachment?
Post Reply
AuthorMessage
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
Posted: · edited   Subject: Delegate a process to a file, for later reattachment? Quote

Is such a think possible under Linux?

Yeah I know I can tmux / nohup, and I know that if I dig deep enough I can manually reattach some of the file descriptors under /proc to get a working terminal for that process again....

... but is there a tool that automatically does this somehow?

e.g.

run -d ./bash long-running.sh  >  proc.file
### later
run -a  proc.file

Edit: Y'all really know how to recreate the feeling of StackOverflow circa 2018

23   Original
pmtriste
lemmy.world
pmtriste@lemmy.world
Joined: 2023-06-13
#2 Posted: · edited   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

The tool is "screen" but it isn't going to a file per se, just a session name.
Edit: I guess tmux does the same. What do you see as the difference? Are you trying to also suspend execution so you can reboot?

2
solrize
lemmy.ml
solrize@lemmy.ml
Joined: 2023-06-22
#3 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

Not sure what you want. You're trying to monitor that process so you can tell when it finishes? You want to know when the file is closed? You can do that with inotify(2).

2
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
#4 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

Not sure what you want. You're trying to monitor that process so you can tell when it finishes? You want to know when the file is closed? You can do that with inotify(2).

I essentially want tmux, without the hassle of needing a tmux server running in the background.

I want the convenience of nohup, with the ability to attach to the nohup file of a running process and recover the running session.

3
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
#5 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

The tool is "screen" but it isn't going to a file per se, just a session name. Edit: I guess tmux does the same. What do you see as the difference? Are you trying to also suspend execution so you can reboot?

the use-case is to simply re-attach to a long-running process, I'm not too concerned about a session persisting across reboots, though that would clearly be amazing

1
solrize
lemmy.ml
solrize@lemmy.ml
Joined: 2023-06-22
#6 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

I essentially want tmux, without the hassle of needing a tmux server running in the background. I want the convenience of nohup, with the ability to attach to the nohup file of a running process and recover the running session.

I use "screen" which i guess is similar to tmux, if that's of any help.

2
frongt
lemmy.zip
frongt@lemmy.zip
Joined: 2025-07-31
#7 Posted: · edited   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

I googled it for you and found this: https://serverfault.com/questions/24425/can-i-nohup-screen-an-already-started-process

It doesn't create a file, but you don't need one. Read all the answers for options on reattaching. I haven't used it, so I can't vouch for any of them. (Personally I just use byobu and have it start with each shell, so I'm always running tmux.)

I don't think there's any system that can reliably freeze a single process to disk. Usually that's implemented by the program itself.

4
refalo
programming.dev
refalo@programming.dev
Joined: 2024-04-13
#8 Posted: · edited   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

https://github.com/nelhage/reptyr

https://github.com/jerome-pouiller/reredirect

https://github.com/trishume/telefork

https://pasky.or.cz/dev/retty/

2
shiny_idea
aussie.zone
shiny_idea@aussie.zone
Joined: 2024-02-28
#9 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

I think the tool "dtach" might fit the bill.

It's supposed to be a lightweight replacement for tmux/screen that only does the detach/reattach parts, and none of the terminal emulation stuff or windowing or any of that.

6
just_another_person
lemmy.world
just_another_person@lemmy.world
Joined: 2023-07-07
#10 Posted: · edited   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

This is a very confusing question. What is the concern about this file, and what do you mean about "reattach"? Is it a long running process? Why would locking thw file, or working in memory of tmp not work? Why is screen not an option?

2
M137
lemmy.today

M137@lemmy.today
Joined: 2026-04-17
Banned
#11 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

[removed by moderator]
-9
CallMeAl (like Alan)
piefed.zip

CallMeAl@piefed.zip
Joined: 2025-12-14
#12 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

I essentially want tmux, without the hassle of needing a tmux server running in the background. I want the convenience of nohup, with the ability to attach to the nohup file of a running process and recover the running session.

hassle of needing a tmux server running

What do you mean? What hassle??

2
Creat
discuss.tchncs.de
Creat@discuss.tchncs.de
Joined: 2023-06-16
#13 Posted: · edited   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

Like many have already said, your probably just looking for a terminal multiplexer. Things like screen or zellij, which to my knowledge also don't require any kind of "server". You start a process and the tool provides means to reattach to the still running sessions.

Any session gets a name, which is what you can use to reattach to a specific one, or you can just "attach" if there isb only one available.

4
pmtriste
lemmy.world
pmtriste@lemmy.world
Joined: 2023-06-13
#14 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

the use-case is to simply re-attach to a long-running process, I'm not too concerned about a session persisting across reboots, though that would clearly be amazing

Screen should work with no problem. You just start the screen session, detatch when you want, reattach later. No problem.

2
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
#15 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

This is a very confusing question. What is the concern about this file, and what do you mean about "reattach"? Is it a long running process? Why would locking thw file, or working in memory of tmp not work? Why is screen not an option?

Imagine you want to launch 1000 long standing processes as oneshots.

Nohup to a file would be a better usage than a screen multiplixier

Why:

  • Because you can do a for loop over the nohup files to grep status and collate stats for the 1000 processes.
  • Because tmux/screen is easy to mentally manage but near impossible to navigate in list view or other

"But you can extract a snapshot of your 1000 tmux windows to file and grep that for status!"

Yes, great, but it's not a neat solution, and tmux/screen snapshots might not capture everything due to window rendering artefacts.

1
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
#16 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

https://github.com/nelhage/reptyr https://github.com/jerome-pouiller/reredirect https://github.com/trishume/telefork https://pasky.or.cz/dev/retty/

oh wow, an actual answer without the classic "this is an X / Y problem" snark!

Re-redirect looks like what I want, thank you kind stranger!

1
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
#17 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

I googled it for you and found this: https://serverfault.com/questions/24425/can-i-nohup-screen-an-already-started-process It doesn't create a file, but you don't need one. Read all the answers for options on reattaching. I haven't used it, so I can't vouch for any of them. (Personally I just use byobu and have it start with each shell, so I'm always running tmux.) I don't think there's any sys...

Cryopid seems promising from that, thanks!

2
just_another_person
lemmy.world
just_another_person@lemmy.world
Joined: 2023-07-07
#18 Posted: · edited   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

Imagine you want to launch 1000 long standing processes as oneshots. Nohup to a file would be a better usage than a screen multiplixier Why: Because you can do a for loop over the nohup files to grep status and collate stats for the 1000 processes. Because tmux/screen is easy to mentally manage but near impossible to navigate in list view or other "But you can extract a snapshot of your 1000 tm...

But what's in this file?

If you're just shuffling data around, use a database.

2
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
#19 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

But what's in this file? If you're just shuffling data around, use a database.

Log data, current status of a run, timestamp of an error, you name it.

These are oneshots. Of course you could use a proper workflow system with data provenance and lineage tracking baked in, but during the dev cycle of something new you usually want to play around and gather metrics first without worrying first about the architecture.

Please don't X/Y me.

1
matcha_addict
lemy.lol
matcha_addict@lemy.lol
Joined: 2023-07-09
#20 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

dtach is exactly what you're looking for.

There are other similar tools. I personally found zmx to be the best, but it's more feature rich than dtach, and might be more than you want. Dtach is pretty minimal. But my only issue with it is it struggles with reloading a terminal session for a TUI that needs non trivial redrawing.

2
tetris11
feddit.uk

tetris11@feddit.uk
Joined: 2025-02-17
#21 Posted:   Subject: Re: Delegate a process to a file, for later reattachment? Quote Reply

dtach is exactly what you're looking for. There are other similar tools. I personally found zmx to be the best, but it's more feature rich than dtach, and might be more than you want. Dtach is pretty minimal. But my only issue with it is it struggles with reloading a terminal session for a TUI that needs non trivial redrawing.

Yeah! It got mentioned earlier, and I've started playing with it -- it's not perfect like you say, but it is good enough for what I need

1
Post Reply Page 1