Process Working Directory

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

Process Working Directory

Post 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?
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Process Working Directory

Post 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.
kubeos
Member
Member
Posts: 138
Joined: Tue Jan 30, 2007 2:31 pm
Location: Kamloops BC, CANADA
Contact:

Re: Process Working Directory

Post 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.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Process Working Directory

Post 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 :|
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Process Working Directory

Post 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?
User avatar
Combuster
Member
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

Post by Combuster »

If you have considered how to pass the initial PWD to the application, then I don't see any problems.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: Process Working Directory

Post 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 :roll:

How do you, guys, handle those?
If something looks overcomplicated, most likely it is.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Process Working Directory

Post by Troy Martin »

Well, my kernel is... unusual...

As of TBOS 1.1.0 (in development hell :twisted: ) the internal shell's command line is passed in SI and the current drive number is passed in DL.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Process Working Directory

Post 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 :roll:

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).
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Process Working Directory

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
skyking
Member
Member
Posts: 174
Joined: Sun Jan 06, 2008 8:41 am

Re: Process Working Directory

Post 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.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Process Working Directory

Post 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.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Combuster
Member
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

Post by Combuster »

Even so, if you are aware of the possibility, you can design it in.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply