appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Logs, journald and strace

Lesson 4 of 411 minAdvanced

Read system logs with journalctl and see what a stuck program is doing with strace.

journalctl

journalctl -u nginx --since "1 hour ago"   # one service, recent
journalctl -p err -b                       # errors since boot
journalctl -f -u myapp                     # follow live
journalctl --disk-usage
  • -u selects a unit, -b the current boot (-b -1 the previous one).
  • -p filters by priority (err, warning, info).
  • Logs may be stored only in memory. Make them persistent with Storage=persistent in /etc/systemd/journald.conf.

strace: what is it doing?

strace prints the system calls a process makes: files it opens, network connections it tries, errors it gets. It often explains a program that fails without a clear message.

strace -f -e trace=openat,connect -o trace.txt ./myprogram
sudo strace -p 1234 -f            # attach to a running process

Search the output for ENOENT (file not found) or EACCES (permission denied) to see which file is the problem.

Carefulstrace slows the target a lot and can show secrets such as passwords in system call arguments. Use it deliberately and do not paste raw output in public.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. How do you see only errors since the last boot?
2. What does ENOENT in strace output mean?
Hintjournalctl with -f and -u.

Key terms