Results 1 to 3 of 3
I am currently running Ubuntu 12.04 and am trying to create a script to output the names of running processes along with their working directories into a file the as ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-22-2012 #1Just Joined!
- Join Date
- Jul 2012
- Posts
- 3
how to output a process's working directory to a file?
I am currently running Ubuntu 12.04 and am trying to create a script to output the names of running processes along with their working directories into a file the as such:
The reason behind this script is to allow me to have access to the working directories of running processes so that I can tell where they are coming from. I'm relatively new to terminal scripting so i'd like to know if i'm on the right track.Code:Process Working Directory firefox /home/pepper/firefox
(I don't know the working directory of firefox, so i used the path above as an example of the format i need.)
- 07-22-2012 #2
Hi and welcome.
You write "working directory", which means the current directory of a process.
It can be changed by the process during runtime, as you can see:
The command ps can list the environment for processes, including pwd:Code:#!/usr/bin/env bash pwd cd /tmp pwd
But there is also a more specialized command: pwdxCode:ps -auwwxe
If all else fails, you can look up the softlink in /proc:Code:pwdx <PID_OF_PROCESS>
ls -ld /proc/<PID_OF_PROCESS>/cwd
Can you please clarify the purpose of your script?
"Where they are coming from" seems a bit vague, as the cwd can change.
Do you mean:
1) What is the cwd at the *start* of a programm/script? This can be done by printing the cwd as the user in question and before the script/programm execution.
Or if all else fails by using a small wrapper that prints the cwd before executing the script/programm.
2) the $PATH of a script/programm. This can be determined by using "which", "find" or the package manager
e.g.
Code:which firefox /usr/bin/firefox dpkg -L firefox | grep bin /etc/apparmor.d/usr.bin.firefox /usr/bin /usr/lib/firefox/distribution/searchplugins/locale/en-US/bing.xml /usr/lib/firefox/components/binary.manifest /usr/bin/firefox
You must always face the curtain with a bow.
- 07-22-2012 #3Just Joined!
- Join Date
- Jul 2012
- Posts
- 3
Basically, I'm trying to write a script that will help me understand the way programs work by providing me with information about where they are located on the drive. Maybe I'm missing something about how linux operates, I'm not sure. I'm rather new with some parts of linux.


Reply With Quote
