Sponsored Content
The Lounge What is on Your Mind? Speculative Shell Feature Brainstorming Post 302509314 by Corona688 on Wednesday 30th of March 2011 01:44:15 PM
Old 03-30-2011
Quote:
Originally Posted by tetsujin
Well, yeah, any program can create a PTY - but if you want to actually display multiple TTY-using programs simultaneously, you need something like screen or xterm - a virtual terminal.
Displaying multiple simultaneous jobs is a rather different process than running multiple simultaneous jobs. Maybe it should be seperate. Either way though it's probably best left 'till last.
Quote:
True... The main use cases I'm thinking about here would be cases where the program expects to display to a TTY.
Hmm. You use 3/4 of the same machinery either way though. And as mentioned, a terminal may not even be necessary.
Quote:
Another way to look at this would be to say it's part of an introduction of proper threading to the shell - meaning that multiple loop iterations running concurrently can modify the variable
As in, no data dependencies or fixed order of operations? You'd need explicit means of synchronization, then.
Quote:
...and if better synchronization is needed, then the user has to write critical regions into their shell code.
Not just critical sections, but means to tell when a section of code has completed to put inside the critical sections.
Quote:
Introducing the concept of threads may complicate other areas of the shell, however: for instance at present if you pipe a bunch of different shell commands together, all but one of those is going to be run in a subshell with no ability to change the environment of the main shell process. Introducing threading would raise the question of whether all those built-in jobs (and even the parenthesis syntax in general) should now be threads.
That could solve a whole lot of problems if you could do it. But you can't avoid creating processes for external commands. It'd also mean you'd lose all the easy ways to scope files and variables, you'd have to have to manage them all brute-force instead of operating with the kernel's support.

I just realized another big problem with running external programs in a threaded shell. fork()ing clones all your threads! You need a mutex or semaphore you can stop all your threads with so you can stop the universe, fork(), redirect and exec in the child, then resume. Or a seperate process you feed commands into with a pipe that creates children for you -- might actually be more efficient than forcing all your threads to run in lockstep.
Quote:
My installed version of wget
AFAIK there's not a bunch of different wgets out there, it's all the GNU wget. They might be compiled with different options -- Windows versions might lack SSL and always print dots -- but they're still the same source code.
Quote:
When there's no TTY (running inside emacs, in this case) the progress bar is redrawn every 50KB or so - on a new line.
You can verify that it's printing dots one-at-a-time with strace:
Code:
$ strace wget http://website/ -O /dev/null > wget.log 2>wget.err 
$ grep "write(2" wget.err | tail
write(2, ".", 1.)                        = 1
write(2, ".", 1.)                        = 1
write(2, ".", 1.)                        = 1
write(2, " ", 1 )                        = 1
write(2, ".", 1.)                        = 1
write(2, ".", 1.)                        = 1
write(2, ".", 1.)                        = 1
write(2, ".", 1.)                        = 1
write(2, ".", 1.)                        = 1
write(2, ".", 1.)                        = 1
$

Something else is doing line-buffering for you, maybe the application you're watching the file with, or maybe a pipe.

So there's only two cases, terminal vs non-terminal, not three, terminal vs pipe vs file. Smilie Whew.
Quote:
If two wgets (with no /dev/tty) are run concurrently with shared stdout, the display winds up corrupted as the two processes write to stdout simultaneously:
Naturally. I'm not sure it's the shell's job to fix this, though. Anyway it's probably not worth worrying about at this point, when there's not even an implementation of the basic no-frills algorithm.
Quote:
If you were running those two programs concurrently while you're at the console, watching, that's not a particularly useful way to display them.
That's not the shell's fault and not the shell's problem, though. If you discovered something with even uglier output, would you add more special modes to accommodate it?

Taking over the terminal that way also means there's no longer one place to type input and one place to read output. That's fine in screen when you created the windows and know what they are, but when they create and destroy themselves in droves, the interface might seem just as bad a scramble as you were trying to fix.

Terminal-using programs like login systems might also end up printing normal prompts in bizarre places because your terminal isn't working the usual way -- or you could not give everything a terminal unless asked for explicitly, in which case they'd just fail to work at all... Or you could give each and every external command its own little shell window on the off-chance that it might need it.

I suppose you could reserve the lower half of the screen for normal console-like I/O but you'd have to emulate it with a pty, which'd turn your shell into a hacking tool -- people could spoof password logins by default. And your shell would look more like an IDE than a terminal.

Not that it wouldn't be useful but maybe these things really do deserve to be separate. It should be kept out of the way and only used where you tell it to explicitly, like a debugging feature, and even then, only when a terminal's available, and with the debug window things output-only.

Another tidbit that could help simplify this a lot is how some terminals can set a scrolling region. It's like a window you can create inside the terminal itself just by printing certain escape sequences. You could set aside the upper half of the screen for some shell window things and use the lower half as a real terminal for things like ssh and passwd to pop up password prompts in.

Of course, only some terminals support this, so it's not portable. You'd also have to carefully time what things get written when.

Bottom line is that taking over the terminal like this means all the usual terminal behavior you take for granted and depend on can't be depended on unless you do it all yourself.
Quote:
(For that matter, that kind of information isn't useful for a log, either...
Funny you should say that, there's actually something on my system that does log wget's dot-lines. Whether it's useful is a matter of taste anyway. It does tell you more information than a single line of progress bar -- it tells you transfer rates over time, not just the average speed.
Quote:
That kind of output is mostly just useful if you want to read it into another program that implements another progress display method.) Really you just want to see the filenames of the files currently being fetched and the progress on each one.
Again remember that you're writing a programming language, not a GUI. People might put it to uses you don't expect, or might not be able to because you didn't give them means to do what they "usually" don't need to. Holding too strictly to things which prettify the terminal could make your language hard to use without one.
Quote:
Still, regardless of whether the output is readable before you interleave it, it's not going to be readable after you interleave it unless you make the right kind of choice about how the values should be interleaved. (Or, in the case of programs that display to the TTY, some kind of TTY-sharing mechanism.)
There's a lot of different ways programs could print output. Do you want to add special modes for all of them, or just give the programmer a way to get at what's there?

Last edited by Corona688; 03-30-2011 at 02:49 PM..
 

4 More Discussions You Might Find Interesting

1. SCO

BASH-like feature. is possible ?

Greetings... i was wondering if there is any shell configuration or third party application that enables the command history by pressing keyboard up arrow, like GNU/BASH does or are there an SCO compatible bash versio to download? where ? just wondering (sory my stinky english) (2 Replies)
Discussion started by: nEuRoMaNcEr
2 Replies

2. Shell Programming and Scripting

Creating a command history feature in a simple UNIX shell using C

I'm trying to write a history feature to a very simple UNIX shell that will list the last 10 commands used when control-c is pressed. A user can then run a previous command by typing r x, where x is the first letter of the command. I'm having quite a bit of trouble figuring out what I need to do, I... (2 Replies)
Discussion started by: -=Cn=-
2 Replies

3. UNIX for Dummies Questions & Answers

brainstorming automated response

I am managing a database of files for which there is a drop-box and multiple users. what i would like to do is set a criteria for files coming into the drop-box based on file structure. (they must be like this W*/image/W*-1234/0-999.tif) If the files do not match the criteria i want them to be... (1 Reply)
Discussion started by: Movomito
1 Replies

4. UNIX for Beginners Questions & Answers

Can we create any check-point feature in shell ?

I have a script as below and say its failed @ function fs_ck {} then it should exit and next time i execute it it should start from fs_ck {} only Please advise #!/bin/bash logging {} fs_ck {} bkp {} dply {} ## main function### echo Sstarting script echo '####' logging fs_ck... (3 Replies)
Discussion started by: abhaydas
3 Replies
All times are GMT -4. The time now is 06:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy