Speculative Shell Feature Brainstorming


 
Thread Tools Search this Thread
The Lounge What is on Your Mind? Speculative Shell Feature Brainstorming
# 22  
Old 04-17-2011
Quote:
Originally Posted by tetsujin
Well, we're talking about using shared memory to export this copy of the shell variables to fork()'ed shell processes - so as long as the memory is shared writable, and as long as access to it is synchronized adequately, those shell processes would be able to propagate their variable changes back to the main shell...
When you make copies of the memory, the memory won't propagate back unless you propagate it yourself. Which opens an even bigger can of worms than just using the originals -- when and if to propagate back.
# 23  
Old 04-18-2011
Quote:
Originally Posted by Corona688
When you make copies of the memory, the memory won't propagate back unless you propagate it yourself. Which opens an even bigger can of worms than just using the originals -- when and if to propagate back.
If it's shared memory you don't make copies. You write to the shared memory and all processes that share that memory see the change. (The same would be true if "subshells" meant to operate on the same environment were threads instead of fork()'ed processes sharing memory - only the sharing mechanism differs.)

If you were saying that the "shell variables" (i.e. the shell's copy of all variables defined in the shell - the working copy shared with all shell processes or threads that are part of the current shell instance) don't propagate back to the "environment variables" (that is, the variables defined in "environ", accessible via C calls to getenv(), etc. in the shell's process) - they don't need to. The only time the shell needs to access its environment variables is at startup, to import those variables into its own working memory. When it runs a command, it forms a new environment including those variables that were exported...

(EDIT): I don't know, maybe I misunderstood you. I guess there is a side to this that I kind of glossed over. Are when you talk about the bigger can of worms, and when to "propagate back" - are you talking about cutting down on the accesses to the shared copy of the shell vars (and related semaphore actions) by pulling things in to a thread-local copy and then writing them back later? I guess that could be a bit of a headache...

Last edited by tetsujin; 04-18-2011 at 03:06 AM..
# 24  
Old 04-18-2011
Quote:
Originally Posted by tetsujin
If it's shared memory you don't make copies.
Quote:
Originally Posted by tetsujin
Of course you could get around it by simply copying all the env. variables to the shell's process memory and operating on those copies of the variables - a bit wasteful but a pretty simple dodge...
Smilie
# 25  
Old 04-18-2011
What I was saying is that in this one specific case we're talking about, where one would implement shell threading by using forked processes and shared memory, you don't need to copy variable assignments back and forth between the processes. You make one copy and share it, using a semaphore system to keep from corrupting it. The only time you have to apply changes to (exported) variables back to the "environment" is when you're about to exec() - in that case you either need to modify the environment (modify "char extern **environ" with setenv(), etc.) to match the in-memory, shared copy, or else create a new environment for the program you're about to run by using execle() and feeding it a copy of those variables.

'Course, the whole thing (dealing with shared memory and fork()'ed processes and so on) sounds like a big headache if what I really want is threads. I suppose I can't count on every host platform having decent threads support, though...
# 26  
Old 04-21-2011
Quote:
Originally Posted by tetsujin
'Course, the whole thing (dealing with shared memory and fork()'ed processes and so on) sounds like a big headache if what I really want is threads.
Synchronization's fairly unavoidable with any sort of multiprocessing by whatever means, be it pipes, mutexes, shared memory...
# 27  
Old 05-04-2011
Quote:
Originally Posted by Corona688
Synchronization's fairly unavoidable with any sort of multiprocessing by whatever means, be it pipes, mutexes, shared memory...
Well, yeah. My point was just that there was no point going through all that - forking and sharing memory - just to simulate threads when I already have threads...
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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
Login or Register to Ask a Question