[opensuse] Process launching directory
Is there a way to find from which directory a process was launched? -- Bogdan Cristea -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Cristea Bogdan wrote:
Is there a way to find from which directory a process was launched?
In what context, within the process or external to the process? - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFHOs0FasN0sSnLmgIRApD4AJ9b8PW2WnjkeZLNEMTz9Hmv0wnsjQCg0Fs7 a5pk/yEEE4FoCTJzQtvNtBM= =0/G7 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
I mean the directory external to the process. I have the same C++
program, with different configurations which I compile and launch from
different directories in order to save the results in different
places. I launch the program with nohup, I can see that there is a
process running in the background, but I can't figure out from which
directory it was launched.
On Nov 14, 2007 11:25 AM, G T Smith
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Cristea Bogdan wrote:
Is there a way to find from which directory a process was launched?
In what context, within the process or external to the process?
- -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone.
Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFHOs0FasN0sSnLmgIRApD4AJ9b8PW2WnjkeZLNEMTz9Hmv0wnsjQCg0Fs7 a5pk/yEEE4FoCTJzQtvNtBM= =0/G7 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-- Bogdan Cristea -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Cristea Bogdan wrote:
I mean the directory external to the process. I have the same C++ program, with different configurations which I compile and launch from different directories in order to save the results in different places. I launch the program with nohup, I can see that there is a process running in the background, but I can't figure out from which directory it was launched.
On Nov 14, 2007 11:25 AM, G T Smith
wrote: Cristea Bogdan wrote: Is there a way to find from which directory a process was launched?
In what context, within the process or external to the process?
As others have indicated not an easy one. If the output files are held open I suppose one could backtrack the open files to the using process using lsof. Personally for this kind of usage I would modify the code either to drop a tag file of some sort or have the working directory defined in the command line so you can hunt down the info via ps. - -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
- -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFHOwj3asN0sSnLmgIRAhB7AKDMFZ0mskqIJmUdCCi4M/AqGrEh0ACfZPSn eReN6j40WiP2k2vCYGvzClE= =Yfjr -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Cristea Bogdan wrote:
I mean the directory external to the process. I have the same C++ program, with different configurations which I compile and launch from different directories in order to save the results in different places. I launch the program with nohup, I can see that there is a process running in the background, but I can't figure out from which directory it was launched.
Have you looked at /proc/[PID GOES HERE] ???? try ls -al /proc/PID | grep cwd where PID is the numeric process ID. note -- not 100% accurate, as a process can change it's current working directory... but for most processes, that's the directory it was called from. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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. Unless the program changes its directory itself, that will be the directory from which it was launched Anders -- Madness takes its toll -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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? CWD usually just points to the process owner's home directory. -- ---Bryen--- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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 Anders -- Madness takes its toll -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
That is correct, I launch the program from the shell and I was looking
for the directory where I stand in when the program is started. The
answer to my question is thus given by: 'ls -l /proc/<pid>/cwd'
On Nov 14, 2007 3:24 PM, Anders Johansson
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
Anders
-- Madness takes its toll --
To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-- Bogdan Cristea -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
"Cristea Bogdan"
11/14/2007 5:20 AM >>> Is there a way to find from which directory a process was launched?
ps -ef|grep process name should display the directory the process started from -Cristian -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (6)
-
Aaron Kulkis
-
Anders Johansson
-
Bryen
-
Cristea Bogdan
-
Cristian Tarhon
-
G T Smith