1- 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
1+ #! /bin/sh
2+ uname && if [ " $( uname) " = " Linux" ]; then
3+ # check if ps exists and can be run on the current target with our selected options, flags is not supported in all ps implementations
4+ ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= > /dev/null 2> /dev/null
5+ ret=$?
6+ if [ $ret -eq 0 ]; then
7+ ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args=
8+ else
9+ # if ps doesn't support the options we are after try and read from /proc/$pid
10+ # Try to mimic the output of ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= from /proc/$pid/ data
11+ echo " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
12+ for pid in ` cd /proc && ls -d [0-9]* `
13+ do {
14+ if [ -e /proc/$pid /stat ]
15+ then
16+ # read values from stat file, directory name matches the pid of each process running
17+ # item 9 kernel flag words of the process, item 2 is the process file name, man proc has more details
18+ flags=` awk ' {print $9}' /proc/$pid /stat` ;
19+ command=` awk ' {print $2}' /proc/$pid /stat | tr -d ' ()' `
20+
21+ # read the process command line used to start the process,
22+ # take the second item for display as argument passed
23+ args=` xargs -0 < /proc/$pid /cmdline | awk ' {print $2}' ` ;
24+
25+ # write values in a format with similar spacing to procps-ng/procps ps
26+ # pid 5 spaces with padding right align, flags 1 char,
27+ # command uses space size of the input of 50 a's -1 from heading left align, args 27 left align
28+ printf " %5s %.1s %-49s %-27s \n\r" $pid $flags $command $args
29+ fi
30+ };
31+ done
32+ fi
33+
34+ elif [ " $( uname) " = " Darwin" ]; then ps -axww -o pid=,flags=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= -c; fi
0 commit comments