On Wed, 2007-11-14 at 15:24 +0100, Anders Johansson wrote:
> On Wednesday 14 November 2007 15:02:01 Bryen wrote:
> > On Wed, 2007-11-14 at 14:44 +0100, Anders Johansson wrote:
> > > On Wednesday 14 November 2007 11:20:08 Cristea Bogdan wrote:
> > > > Is there a way to find from which directory a process was launched?
> > >
> > > It depends on what you mean, really. If you mean "what was the current
> > > working directory when the process was launched", then the answer is no,
> > > you can't
> > >
> > > You can find the current working directory of the process, by doing
> > >
> > > ls -l /proc/<pid>/cwd
> > >
> > > where <pid> is the process id of the process.
> >
> > Wouldn't 'ls -l /proc/<pid>/exe give the result he wants?
> 
> No, that just says where the binary is. That wasn't what he was looking for
> 
> > CWD usually 
> > just points to the process owner's home directory.
> 
> No, it points to the current working directory of the process. That is by 
> default the same as the current working directory of the parent process, but 
> can be changed by the process itself (that was why I said it was impossible 
> in general, if the process changes it, there is no way of finding out where 
> it was launched from)
> 
> If the parent process is the KDE or gnome menus, then the working directory 
> is 
> the home directory, but at least in the KDE menu, you can change that in the 
> properties of the link
> 
> But in this case he said he was running it from different directories because 
> he wanted the program to store the output in those directories. That means he 
> is probably running it from the shell, in which case that shell is the parent 
> process, and the cwd is the directory he is standing in when he starts the 
> program
> 
Ahh... Okay.  See, that's why we're all here.  To learn something new
everyday.  :-)

-- 
---Bryen---

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to