Page 1 of 1
Process Working Directory
Posted: Thu May 21, 2009 12:38 pm
by kubeos
Well, I finally got around to fixing my old multitasking code. Everything SEEMS to be working fine now.
But I'm wondering what others have done about a process's current working directory. If I launch a program in the background and it is working with files, then I change to a different directory in my shell, things can really get messed up. What I was thinking of doing is, when a program is launched, it records the current drive and directory into it's process structure. Every time the program needs to save or load a file, the kernel will change to the program's directory. If the program changes directory, then that will replace what was originally recorded.
Is this similar to what anyone else has done?
Re: Process Working Directory
Posted: Thu May 21, 2009 1:13 pm
by NickJohnson
That is usually how it works - the working directory is stored in each process structure, and changing one won't change the others.
Re: Process Working Directory
Posted: Thu May 21, 2009 1:27 pm
by kubeos
Okay, I just started coding it up. Works like a charm so far. lcc is compiling and linking a test program perfectly while I'm in a different directory.
Re: Process Working Directory
Posted: Thu May 21, 2009 9:40 pm
by Troy Martin
Another solution: don't implement directory support
I'm already regretting that route and I'm writing a simple LFN/directory layer to fix that
Re: Process Working Directory
Posted: Fri May 22, 2009 9:23 am
by skyking
Another solution may be to implement the current directory in user space. That is letting the C library have a global variable that is used to convert filenames to absolute filenames before accessing the file. That's what I've planned to use and I don't see any big problems with that. Do you?
Re: Process Working Directory
Posted: Fri May 22, 2009 10:09 am
by Combuster
If you have considered how to pass the initial PWD to the application, then I don't see any problems.
Re: Process Working Directory
Posted: Fri May 22, 2009 11:25 am
by Velko
I'm planning to implement working directory in userspace as well. But, instead of using plain global variable I'm going to use PWD environment variable.
There's one "small" problem trough - I haven't figured out a decent way to pass environment variables to new process yet
How do you, guys, handle those?
Re: Process Working Directory
Posted: Fri May 22, 2009 4:03 pm
by Troy Martin
Well, my kernel is... unusual...
As of TBOS 1.1.0 (in development hell
) the internal shell's command line is passed in SI and the current drive number is passed in DL.
Re: Process Working Directory
Posted: Sat May 23, 2009 5:30 am
by skyking
Velko wrote:I'm planning to implement working directory in userspace as well. But, instead of using plain global variable I'm going to use PWD environment variable.
There's one "small" problem trough - I haven't figured out a decent way to pass environment variables to new process yet
How do you, guys, handle those?
Well simply add a few parameters to create_process that then is used as parameter to the process entry point. For example you could set a pointer and data length and fill the memory block with whatever you would like (environment, command line parameters etc).
Re: Process Working Directory
Posted: Sun May 24, 2009 5:26 am
by Kevin
In tyndur, the initialization code of the new process asks its parent for the environment variables via normal IPC functions. The current working directory is one of them.
Re: Process Working Directory
Posted: Sun May 24, 2009 2:17 pm
by skyking
Kevin wrote:In tyndur, the initialization code of the new process asks its parent for the environment variables via normal IPC functions. The current working directory is one of them.
This might result in a race condition if the parent changes the working directory (or even terminates) between the start of the child and the IPC-message.
Re: Process Working Directory
Posted: Sun May 24, 2009 3:38 pm
by Kevin
True. You can have hacks in place that "work for now", but you should never forget they are hacks, like I did here.
Re: Process Working Directory
Posted: Sun May 24, 2009 3:44 pm
by Combuster
Even so, if you are aware of the possibility, you can design it in.