[SOLVED] How to start new process, independent of current? 04 September 2021, 22:32:20 I am using a file manager, currently `lf` but doesn't matter. I want to create more instances using some arguments from current file manager or terminal.If I type `pwd | st`, it opens a new terminal (`st` is my terminal, idk what it stands for), but when I close the terminal where I wrote this, it closes the child process as well (`st`). Is there a simple way to make it independent? As if I popped a new terminal via keyboard shortcut? E.g. if I open `st` via dmenu, I can open any amount without being linked.This question is more of linux practice/workflow question, nothing specific, and honestly its not a dealbreaker Last Edit: 09 September 2021, 17:18:37 by TheYellowArchitect
Re: How to start new process, independent of current? Reply #1 – 04 September 2021, 23:33:13 So on Linux when you use a process to spawn another process, that new process is owned by the older one.When you kill a process, you are actually instructing the process to also kill anything that it spawned.This makes sense intuitively right? If I start a program via my terminal and it freezes, then I might actually kill the terminal, to kill that terminal.Now as you have rightly pointed out, there are times when we actually don't want this behaviour to occur.When this is the case there are two ways to go about it.The simplest (and for your case probably what you're looking for) is the use of the Code: [Select]disowncommand. This tells your current shell to well, disown its child processes. This is as easy as entering the command, however it requires you to have run anything you want to disown asynchronously (in the background) using & at the end of the command.The other way would be to look into terminal multiplexers such as Tmux and GNU Screen, but for your example they are very much overkill.They are very useful programs, especially on remote servers, so I'll leave researching them as an exercise to the reader.
Re: How to start new process, independent of current? Reply #2 – 05 September 2021, 11:53:53 Quote from: TheYellowArchitect – on 04 September 2021, 22:32:20If I type `pwd | st`, it opens a new terminal (`st` is my terminal, idk what it stands for), but when I close the terminal where I wrote this, it closes the child process as well (`st`). Is there a simple way to make it independent? As if I popped a new terminal via keyboard shortcut? E.g. if I open `st` via dmenu, I can open any amount without being linked.This question is more of linux practice/workflow question, nothing specific, and honestly its not a dealbreaker1. Why would you pipe the output of pwd(1) (Print Working Directory) into a terminal emulator? It doesn't make any sense. st doesnt read stdin from a pipe. Maybe workingdir patch is what you are looking for.2. How can you not know what does st stand for, and you are using it (implying downloading and compiling it to install it)? It's right there on its webpage: https://st.suckless.org/3.Code: [Select]$ man 1 nohupQuote from: Krellnus – on 04 September 2021, 23:33:13Code: [Select]disowndisown is a Bash builtin. Those that use other shells (I'm using mksh for example) don't have access to it. Last Edit: 05 September 2021, 12:08:48 by strajder 1 Likes
Re: How to start new process, independent of current? Reply #3 – 05 September 2021, 12:35:46 Quote from: strajder – on 05 September 2021, 11:53:53disown is a Bash builtin. Those that use other shells (I'm using mksh for example) don't have access to it.Really? I wasn't aware of that, since it's also available in zsh (which is what I use). Thanks for the heads up.
Re: How to start new process, independent of current? Reply #4 – 05 September 2021, 20:23:13 Quote from: Krellnus – on 05 September 2021, 12:35:46Really? I wasn't aware of that, since it's also available in zsh (which is what I use). Thanks for the heads up.Well, at the very least it shouldn't be expected to be found in every shell. It isn't a part of POSIX.You can check that it is a builtin (or not supported) by issuing the commandCode: [Select]$ type disownin your shell.Edit: To be more precise, disown is mentioned, but only in one place, in the section Command Search and Excecution, and with the context thatQuoteIf the command name matches the name of a utility listed in the following table, the results are unspecified.I have additionally tested ksh93, and it has the disown builtin, while mksh and dash do not. Last Edit: 06 September 2021, 15:07:45 by strajder
Re: How to start new process, independent of current? Reply #5 – 08 September 2021, 21:02:25 QuoteThe simplest (and for your case probably what you're looking for) is the use of the `disown` command This tells your current shell to well, disown its child processes. This is as easy as entering the command, however it requires you to have run anything you want to disown asynchronously (in the background) using & at the end of the command.This doesn't work, e.g. `st disown &` or `lf disown &` though it is a good idea.Did I use the command wrong?Quote1. Why would you pipe the output of pwd(1) (Print Working Directory) into a terminal emulator? It doesn't make any sense.True, it was an example. But ultimately, the most common use of my question, is that I want to mirror my process, e.g. while being in a terminal to pop another terminal in the same file location (`st`) but when I close one, the other also closes lolAlso, same for `lf`, I want to open another one in its place, and the only way I know is `!lf` but if I close one, ggwp.Quote3. man 1 nohupIt opens another process, and it does become independent, but current process becomes uninteractive. At least, this is from my usage of `nohup st` or `nohup lf`Edit: `nohup lf &` ggwp, bless the & symbol, I wouldn't think of it if not mentioned above, thank you both <3Edit2: This is bizzare. The right above command doesn't work. I tested it once to confirm it worked and to type above, but I'm pretty sure it worked back then, maybe I pressed st instead lol. Anyway, `nohup st &` works at least Last Edit: 08 September 2021, 21:49:38 by TheYellowArchitect
Re: How to start new process, independent of current? Reply #6 – 08 September 2021, 21:56:19 Prepend command using setsid, `man setsid`. Might want to add -f option. Process can then be put to background ('&') , and/or output sent to >/dev/null 2>&1 if needed. 1 Likes
Re: How to start new process, independent of current? Reply #7 – 08 September 2021, 23:41:42 To really completely background something it should be double forked, but I'm not sure the best way to do that in a shell script, and it may be more than you need to do anyway.https://stackoverflow.com/questions/3430330/best-way-to-make-a-shell-script-daemon"daemon" builds OK from the AUR and works simply, just using daemon <command> seemed to work.https://aur.archlinux.org/packages/daemon/ 1 Likes
Re: How to start new process, independent of current? Reply #8 – 09 September 2021, 01:09:55 Quote from: TheYellowArchitect – on 08 September 2021, 21:02:25This doesn't work, e.g. `st disown &` or `lf disown &` though it is a good idea.Did I use the command wrong?Oh my bad, I should have been more explicit.You useCode: [Select]st &To return the console to you, then you use.Code: [Select]disown 1 Likes
Re: How to start new process, independent of current? Reply #9 – 09 September 2021, 17:18:20 Thanks you very much for the help, aside of learning new things, I got 3 ways to pretty much mirror the terminal, which is pretty much what I wanted. Before this thread, I literally opened a new terminal and had to browse manually to the same terminal location... So, not having to do this every time I want to open another file at the same time (very frequent) will save me tons of time. Thank you!
Re: [SOLVED] How to start new process, independent of current? Reply #10 – 09 September 2021, 20:53:18 I often do this kind of thing too, for file managers in the current directory, but for terminals, such as xfce4 terminal, mate terminal, terminator, gnome terminal, I use tabs - just hit SHIFT_CTRL_T or use the right click menu, and a new tab is opened in the current directory. It can also be "torn off" to make a new terminal window or slid along to re-order on the tab bar. SHIFT_CTRL_W to close quickly. Not all terminals / window managers may support all this, also you can use terminals from other desktops if you want, it's generally better to use GTK or QT to match the desktop for less deps, but that's not essential.
Re: [SOLVED] How to start new process, independent of current? Reply #11 – 09 September 2021, 21:51:21 Quote from: ####### – on 09 September 2021, 20:53:18I often do this kind of thing too, for file managers in the current directory, but for terminals, such as xfce4 terminal, mate terminal, terminator, gnome terminal, I use tabs - just hit SHIFT_CTRL_T or use the right click menu, and a new tab is opened in the current directory. It can also be "torn off" to make a new terminal window or slid along to re-order on the tab bar. SHIFT_CTRL_W to close quickly. Not all terminals / window managers may support all this, also you can use terminals from other desktops if you want, it's generally better to use GTK or QT to match the desktop for less deps, but that's not essential.Or launch a new st instance in dwm with Shift+Mod+Enter.