Ubuntu 서버에서 트랜스 코딩을 실행하고 때로는 프로세스가 부실하고 출력을 제공하지 않지만 ps aux
프로세스가 여전히 실행 중임을 표시하지만 CPU 사용량이 부실합니다.
다음 명령을 사용하여 CPU 사용량을 가져올 수 있습니다 (작업중인 ffmpeg 프로세스에는 프로세스 ID 4416이 있습니다.
ps aux | grep -v grep | grep 4416 | awk '{print $3}'
그리고 특정 프로세스를 죽이는 작은 스크립트를 만들 수 있지만 각 ffmpeg 프로세스를 확인하고 부실한 경우 종료하는 루프를 어떻게 생성합니까 (runit가 나중에 다시 시작합니다)?
1 분 크론으로 CPU 사용량을 두 번 얻고 CPU 사용량이 같으면 프로세스를 종료하려면 명령을 실행해야한다고 생각합니다. 이거할까요?
좋습니다. 몇 가지 ps aux
요청을 한 다음 오래된 프로세스를 확인합니다.
#!/bin/bash
# setup, change this if undesired
workdir="/tmp/.stale_process_killing"
[ -d "$workdir" ] || mkdir "$workdir"
# get ps aux outputs, change number of iterations if desired
for ((i=1; i<5; i++)); do
# add file number to file
echo $i > "${workdir}/psaux${i}"
# add ps output to file
ps aux | grep 'ffmpeg' >> "${workdir}/psaux${i}"
# change this timeout to suit your needs
sleep 1
done
# now parse the files using awk
awk '
FNR==1 { ix = $1 }
FNR!=1 { cpu[$2][ix] = $3 }
END {
for (pid in cpu) {
j=1;
while (cpu[pid][j] == cpu[pid][j+1] && j <= ix) {
if (cpu[pid][j++] == "") {
j=1;
break;
}
}
if (j >= ix) {
system("kill " pid);
}
}
}' "${workdir}/psaux"*
안전하게 확인하기 위해 디버그 인쇄가 포함 된 버전입니다.
#!/bin/bash
# setup, change this if undesired
workdir="/tmp/.stale_process_killing"
[ -d "$workdir" ] || mkdir "$workdir"
# get ps aux outputs, change number of iterations if desired
for ((i=1; i<5; i++)); do
# add file number to file
echo $i > "${workdir}/psaux${i}"
# add ps output to file
ps aux | grep 'ffmpeg' >> "${workdir}/psaux${i}"
# change this timeout to suit your needs
sleep 1
done
# now parse the files using awk
awk '
FNR==1 { ix = $1 }
FNR!=1 { cpu[$2][ix] = $3 }
END {
for (pid in cpu) {
j=1;
while (cpu[pid][j] == cpu[pid][j+1] && j <= ix) {
print cpu[pid][j]
if (cpu[pid][j++] == "") {
j=1;
break;
}
}
if (j >= ix) {
print "kill " pid;
} else {
print "no kill " pid;
}
}
}' "${workdir}/psaux"*
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다