You are not logged in.

#1 2008-09-22 04:10:33

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Terminal scripting issue - idea failed, need help

Okay, so I recently got the cool idea to put my terminals inside dtach (screen minus the bloat, just the ability to detach), so I could, among other, unrelated, reasons that ultimately failed because of design, connect to them remotely with zero work or make them available to friends so they could watch or interact with me for whatever reason. And I also liked the idea because it meant that my bash started up alongside my terminal emulator, not after, so I reduced terminal launch times from the likes of 2000ms (ouch) to maybe 600-1200ms, which is nice.

Only problem is, because dtach is designed to... dtach, it:
1, won't kill the session/shell it's controlling when I exit my terminal if that shell is in the middle of something, whether good or bad
2, has issuez with backgrounded processes - "someprogram & exit" will result in "someprogram & leave_terminal_visible_and_hung_on_screen" instead.

I fixed #2, but can't for the life of me figure out how to fix #1. For example, say I run something that I don't realize is gonna kill my system, like "ls `yes`". I'm like "meep, that was a bad idea" and hit the terminal close button, then I'm like "MEEP, it's STILL RUNNING", and have to scramble to get htop open so I can find what copy of bash is eating 2734643958274% RAM and kill -9 it manually.

Well, I did have an idea on how to fix #1 using scripting, but then I realized that I have no way to figure out if the terminal has been closed, if I use scripting.

So, I'm not looking for the ability to dtach completely, pretty obviously. I'm looking for some way to achieve:

* Open terminal. My shell and the terminal start at the same time (asynchronously, like with dtach)
* Others can connect to my terminal somehow, like screen or dtach would let them (by running screen -x or dtach -a)
* When other user(s) detach from my session, the terminal doesn't change or exit in any way.
* When I or someone else causes the shell to quit, the terminal does close.
* When I close my terminal, everything closes as it should, killing my shell as normal but NOT closing backgrounded apps (as normal).
* If I run an application backgrounded then close the terminal either by exiting bash or closing the terminal window, my terminal doesn't hang on the screen, requiring me to close it, hunt down what copy of dtach was the parent of the backgrounded process, kill it, and hope the copy of bash it spawned got killed too.

I'll be pretty... amazed if you have any ideas. big_smile

-dav7

Last edited by dav7 (2008-09-22 04:25:58)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

Board footer

Powered by FluxBB