ps -ef 값이 출력되지 않는 문제

KiJeong·2021년 11월 8일
1

Linux

목록 보기
5/8

문제

터미널의 width 크기에 따라 ps -ef 값이 출력되지 않을 때가 있었다.

분석

처음엔 pipe 명령때문인가, 아니면 grep 명령인가, 아니면 > out.txt 이용해서 파일로 저장하면 괜찮아 질까 하고 해봤는데 파일로 저장해도 결과는 똑같았고, pipe 명령도 grep 명령도 문제는 아니었다.

-ef를 사용하지 말고 다른 명령어를 사용해볼까 해서 다른 명령어도 사용해봐도 결과는 마찬가지였다.

$ ps aux | grep 'something'

참고 링크

해결

ps 명령어는 출력되는 column 이 제한된다는 사실을 알았다.

그래서 ps -ef 명령을 사용하지 않고 ps --column=300 이렇게 column의 길이를 설정해주니까 잘 출력이 되었다.

ps --columns 300 -e -o cmd | grep

참고

stackoverflow 답변

This might be a long shot in your case but I had same experience with "ps -ef" in the past (don't remember the exact OS type where I seen it, but my script had to work on any Linux, AIX, Solaris and HP-UX).

The "ps -ef" output might be limited to a certain number of columns when used inside a script executed without a terminal. The user, pid, ppid, cputime columns are dynamic and breaking the format sometimes (when the data is larger then the reserved space). For example if the PID of the process gets to large then the name of the process might be "cut" so that it doesn't appear in the already limited number of column displayed by "ps -ef" then your monitor script would fail.

You could try to keep the file containing the "ps -ef" output and check if it's this problem. No need to wait for when the issue happens, just check if you have the extra long process names in the file (anything longer then the process you're looking for).

My workaround for this problem is to specify a large enough number of columns to be used, like this: COLUMNS=8192 ps -ef > file.out the variable is set just for this 1 purpose.

0개의 댓글