Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fallback for ps in remoteProcessPickerScript #5207

Merged
merged 3 commits into from
May 16, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion scripts/remoteProcessPickerScript
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
uname && if [ "$(uname)" = "Linux" ] ; then ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= ; exit; elif [ "$(uname)" = "Darwin" ] ; then ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= -c; fi
#!/bin/sh
uname && if [ "$(uname)" = "Linux" ]; then
# check if ps exists and can be run on the current target with our selected options, flags is not supported in all ps implementations
ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= >/dev/null 2>/dev/null
ret=$?
if [ $ret -eq 0 ]; then
ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args=
else
# if ps doesn't support the options we are after try and read from /proc/$pid
# Try to mimic the output of ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= from /proc/$pid/ data
echo " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
for pid in `cd /proc && ls -d [0-9]*`
do {
if [ -e /proc/$pid/stat ]
then
# read values from stat file, directory name matches the pid of each process running
# item 9 kernel flag words of the process, item 2 is the process file name, man proc has more details
flags=`awk '{print $9}' /proc/$pid/stat`;
command=`awk '{print $2}' /proc/$pid/stat | tr -d '()'`

# read the process command line used to start the process,
# take the second item for display as argument passed
args=`xargs -0 < /proc/$pid/cmdline | awk '{print $2}'`;

# write values in a format with similar spacing to procps-ng/procps ps
# pid 5 spaces with padding right align, flags 1 char,
# command uses space size of the input of 50 a's -1 from heading left align, args 27 left align
printf "%5s %.1s %-49s %-27s \n\r" $pid $flags $command $args
fi
};
done
fi

elif [ "$(uname)" = "Darwin" ]; then ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= -c; fi