·터미널 명령어

strace

프로세스·시스템

쓰는 꼴

strace [-f] -p <pid>

프로세스가 커널에 던지는 시스템 호출을 하나씩 찍어 어디서 멈췄는지 보여줍니다 — 출력이 stderr로 나가므로 `2>&1`로 돌려야 하고, ptrace 권한(보통 sudo)이 필요하며 Linux 전용입니다(macOS는 dtruss).

자주 쓰는 옵션

옵션
-p <pid>Attach to a process that is already running.
-fFollow child processes and threads too.
-e trace=openat,connectOnly the syscalls you care about.
-s 200Show 200 characters of each string instead of the default 32.
-o <file>Write to a file, since output goes to stderr.
-cA summary count per syscall instead of every line.
-ttTimestamps with microseconds, to see where the time went.

예시

strace -f -e trace=openat ./app 2>&1 | grep config

Find which config file it actually reads.

sudo strace -p 1234 -s 200

See what a stuck process is waiting on.

sudo dtruss -p 1234

The macOS counterpart; needs elevated privileges and often SIP changes.

무엇이 돌고 있고 무엇이 자원을 먹는지 봅니다. 죽이기 전에 무엇인지 확인하는 것이 순서입니다.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. strace은 무엇을 하나요?

프로세스가 커널에 던지는 시스템 호출을 하나씩 찍어 어디서 멈췄는지 보여줍니다 — 출력이 stderr로 나가므로 `2>&1`로 돌려야 하고, ptrace 권한(보통 sudo)이 필요하며 Linux 전용입니다(macOS는 dtruss).

Q. 어떻게 치나요?

strace [-f] -p <pid> — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 7개입니다. 전체 목록은 man strace에 있습니다. 이 명령은 프로세스·시스템 갈래입니다.

같이 보는 명령

man 페이지: man strace