I need to display processes, that are running in specific folder. For example, there are folders "TEST" and "RUN". 3 sql files are running from TEST, and 2 from RUN. So when I use command ps xa, I can see all processes, runned from TEST and RUN together. What I want is to see processes, runned only from TEST folder, so only 3. Any commands, solutions to do this?
Asked
Active
Viewed 1,486 times
-1
-
1https://unix.stackexchange.com/questions/94357/find-out-current-working-directory-of-a-running-process – William Pursell Sep 20 '18 at 15:34
-
Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Sep 20 '18 at 16:12
2 Answers
1
You can use lsof
for this.
lsof | grep '/path/of/RUN'
.
If you want to include both RUN and TEST in same command
lsof | grep -E "/path/of/RUN|/path/of/TEST"
Hope it helps.

Raja G
- 5,973
- 14
- 49
- 82
0
You can try fuser
to see which processes have particular files open; or, on Linux, examine the /proc/12345/cwd
symlink for each of the candidate processes (replace 12345
with the process id of each).
fuser TEST/*.sql
for proc in /proc/[1-9]*; do
readlink "$proc/cwd" | grep -q TEST && echo "$proc"
done
The latter is not portable to other U*xes, though some may offer similar facilities.

tripleee
- 175,061
- 34
- 275
- 318