過去 5 時間以内に開始された処理を確認するにはどうすればよいですか? それはできps
ますか?
ps -ef | grep <username>
のすべてのプロセスを表示するものを使用する必要があります。次に、STIME列を手動で確認する必要があります
ps -eo etime,pid
すべてのPIDを、プロセス作成からの経過時間とともにの形式で一覧表示します[[DD-]hh:]mm:ss
。トリッキーな日付比較を実行する代わりに、5:00:00未満の時間量を検索できるため、これは便利な場合があります。
stat -t /proc/<pid> | awk '{print $14}'
エポックからのプロセスの開始時間を秒単位で示します。現在の時刻()と比較してdate +%s
、プロセスの経過時間を秒単位で見つけます。
多分これはあなたを助けるでしょう:
ps -aef を実行します。これにより、プロセスが開始された時間が表示されます。次に、date コマンドを使用して現在の時刻を見つけます。2 つの差を計算して、プロセスの年齢を見つけます。
クレジットは次のとおりです。特定の年齢よりも古いすべての Linux プロセスをどのように強制終了しますか?
笑いのために、これは私がいくつかの古代のシステム(aixとsolarisの両方)でやらなければならなかったことであり、今まではほぼ「大丈夫」に思えます...(しかし、将来何かが変わると失敗するかもしれません。また、プロセスが999日以上続くマシンではすでに失敗していると思います...見つけたら修正します)
それらの古代のシステムでは:
以下の小さなことは、これらのケース(およびその他)を処理します...しかし、本当に醜いです^^
編集:新しいバージョン(少し正気で用途が広いですが、何かを使用できるようにするためにps出力を多く処理する必要があることを示しています...表示される情報の数を変更する奇妙な方法があるため...)
max_size_var_awk="399" #old awk (and nawk) limit of a var size ?!
ps_output_prettifier="%10s %8s %8s %3s %-14s %11s %10s %s\n" #11s for /dev/pts, as it could also be "zoneconsole" in a solaris zone...
truncated_mark="(...)"
size_to_truncate=$(( ${max_size_var_awk} - ${#truncated_mark} ))
tmpfile=
#get the ps output
ssh localhost "ps -elo user,pid,ppid,nice,etime,tty,time,args" \
| awk '(NF==5) { $8=$5;$7=$4;$6="-";$5="000-00:00:0-";$4=$3;$3=$2;$2=$1;$1="-"; }
{ print $0}' \
| sed -e 's/^ *//' >"${tmpfile:-/tmp/defaulttmp.$$}"
#we read the ps output, putting the first few items in their respective var, and the rest (cmd + args) in "_rest"
while read _u _p _pp _n _e _tt _ti _rest ; do
#special case: we just read the first line:
[ "$_ti" = "TIME" ] && {
printf "${ps_output_prettifier}" "$_u" "$_p" "$_pp" "$_n" "99999__$_e" "$_tt" "$_ti" "$_rest"
continue
}
#for all the other lines:
</dev/null nawk -v u="$_u" -v p="$_p" -v pp="$_pp" -v n="$_n" -v e="$_e" -v tt="$_tt" -v ti="$_ti" -v template="00000-00:00:00" \
-v rest="$(printf "%s" "$_rest" | cut -c 1-${size_to_truncate})" -v lrest="${#_rest}" -v trunc="${truncated_mark}" -v totrunc="${size_to_truncate}" \
-v ps_output_prettifier="${ps_output_prettifier}" '
BEGIN { rem="we add the beginning of the template to the beginning of the etime column..."
prefix=substr(template,1,length(template)-length(e)) ; e=prefix e;
rem="and add the message IF it was truncated"
if (lrest>totrunc) { rest=rest trunc ; }
rem="modify -hh:mm:ss into .hhmmss to allow sort -n to operate on all (and not just on nb-of-days)"
sub(/-/,".",e) ; sub(/:/,"",e) ; sub(/:/,"",e)
printf (ps_output_prettifier,u,p,pp,n,e,tt,ti,rest);}'
done <"${tmpfile:-/tmp/defaulttmp.$$}" \
| sed -e 's/^/ /' | sort -k5,5nr \
| sed -e 's/ \([0-9][0-9][0-9][0-9][0-9]\)\.\([0-9][0-9]\)\([0-9][0-9]\)/ \1-\2:\3:/'
古いバージョン:
複雑な sed (最後のものと同様) は、整列を維持しようとします (そして、出力は ps よりも整列されます)。(可能であれば awk を使用しますが、$1、$2、...、または $0 で何かを変更すると行全体が再計算されるため、アライメントを簡単に維持することはできません。単純なことを行い、すべてを a 経由で処理する必要があるかもしれませんprintf を再調整するのは簡単ですか?....後でそれを行います! (しかし、長い args 行が混乱するのではないかと心配しています...そして、printf に「最初のいくつかの引数をフォーマットするだけで、他のすべてをそのまま最後の %s に入れます")
プロセスの日付が24時間以内かどうかにかかわらず、1つまたは2つの列があり、間隔が再びすべて間違ってしまい、最後の sed が失敗するため、通常の ps 'time' を追加するのはかなりの作業になります。など
LC_ALL=C
ps -eo user,pid,ppid,nice,etime,tty,time,args \
| sed -e 's/^\( *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]*\) \([0-9]-\)/\1 00\2/' \
-e 's/^\( *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]*\) \([0-9][0-9]-\)/\1 0\2/' \
-e 's/^\( *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]*\) \([0-9][0-9]:\)/\1 000-\2/' \
-e 's/^\( *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]*\) \([0-9][0-9]:\)/\1 000-00:\2/' \
-e 's/^\( *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]* *[^ ][^ ]*\) -/\1 0?_-__:__:__/' \
| sed -e 's/^/ /' | sed -e 's/\([0-9]\)-/\1./' | sed -e 's/\([0-9][0-9]\):\([0-9][0-9]\):/\1\2/' \
| sed -e 's/NI ELAPSED/NI 999._ELAPSED/' \
| sort -k5,5nr \
| sed -e 's/\( [0-9][0-9][0-9]\)\.\([0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\) /\1-\2:\3:\4 /' \
| sed -e 's/^ *\([^ ][^ ]*\)\( *\)\([^ ][^ ]*\)\( *\)\([^ ][^ ]*\)\( *\)\([^ ][^ ]*\)\( *\)\([^ ][^ ]*\)$/ ________ \1 \3 \5 0?_-__:__:__ - \7 \9/'
お楽しみください ^^ [それはまだ進行中です... これまでのところ動作しますが、他のシステム (Linux? aix & solaris の他のバージョンなど) では試すことができませんでした]