Already posted it as a comment, this should do what you want:
ps -ef | grep "$(ls)"
Я хочу получить статус процесса для всех служб, работающих в данном каталоге. Прямо сейчас я могу проверить один за другим ps -ef | grep ServiceName
. Но есть ли путь к ls
каталогу и ps
каждому сервису?
Что-то вроде ps -ef | grep < ls
?
Already posted it as a comment, this should do what you want:
ps -ef | grep "$(ls)"
In Bash:
ps -ef | grep "$(ls)"
(The same line appeared in incBrain's comment while I was composing and testing the rest of my answer in Debian/Bash.)
It will generate garbage if the pattern appears in ps
output as a command line argument (not the command) or as a part of the command. To reduce this I would use find
instead of ls
to obtain full path:
ps -ef | grep -f <(find -L "$(pwd)" -maxdepth 1 -type f)
Still there may be some unwanted extra output.
Note that these are not
services running in a given directory
rather processes with executables in a given directory.
To tell current working directory of a process you may read /proc/<PID>/cwd
. Next example is (quick and dirty) ps
alternative and it shows that you can extract information from /proc
in a form you want:
sudo bash -c 'for i in /proc/[1-9]* ; do PID=$(basename "$i"); E=$(readlink "$/exe"); D=$(readlink "$/cwd"); echo -e "PID=$\tEXE=$\tCWD=$" ; done | grep "CWD=$(pwd)$"'
You need sudo
to get access to all processes. If this isn't necessary and you want to run it as regular user, the part within '
delimiters is enough.
Maybe something like this:
processes="$(ps -ef)" for file in *;do grep "$file" <<<"$processes" done