Process Working Directory
Process Working Directory
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?
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?
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Process Working Directory
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
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.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Process Working Directory
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
I'm already regretting that route and I'm writing a simple LFN/directory layer to fix that
Re: Process Working Directory
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?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Process Working Directory
If you have considered how to pass the initial PWD to the application, then I don't see any problems.
Re: Process Working Directory
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?
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?
If something looks overcomplicated, most likely it is.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Process Working Directory
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.
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
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).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?
Re: Process Working Directory
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
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.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.
Re: Process Working Directory
True. You can have hacks in place that "work for now", but you should never forget they are hacks, like I did here.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Process Working Directory
Even so, if you are aware of the possibility, you can design it in.