System Calls
Chapter 17: Syscalls and Kernel Interface
System calls are the only legitimate boundary between user programs and the kernel โ every open(), read(), and write() involves a privilege-level switch. This chapter starts from the x86_64 ABI, then covers full strace call-chain analysis, the /proc virtual filesystem, sysctl kernel parameter tuning, the /sys device tree, kernel module management, and dmesg log interpretation โ all tied together by a complete production "file descriptor leak" investigation.
1. Syscall Internals
User Mode vs Kernel Mode
Modern CPUs isolate user code from kernel code via privilege rings (x86 calls them Rings). User programs run in Ring 3 (lowest privilege); the kernel runs in Ring 0 (highest privilege). Ring 3 code cannot directly access hardware or other processes' memory โ it must trap into the kernel via a system call. This mechanism is both a security boundary and a performance cost: each syscall averages 100โ300 ns (register save, TLB flush, context switch, etc.).
Two Syscall Trigger Mechanisms
| Instruction | When Used | Performance |
|---|---|---|
| int 0x80 | Legacy 32-bit x86, traps via software interrupt | Slower (~1 ยตs) |
| syscall | x86_64 fast path, switches via MSR registers directly | Fast (~100โ300 ns) |
| VDSO | Kernel maps some calls (e.g. gettimeofday) into user address space โ no kernel entry at all | Extremely fast (nanoseconds) |
x86_64 Syscall ABI Convention
x86_64 Linux uses the following register convention to pass the syscall number and arguments (defined in /usr/include/asm/unistd_64.h):
- rax: syscall number (e.g. read=0, write=1, open=2, fork=57)
- rdi, rsi, rdx, r10, r8, r9: 1stโ6th arguments
- rax (return value): non-negative on success, -errno on failure
# ๆฅ็ๆๆ็ณป็ป่ฐ็จๅท๏ผx86_64๏ผ
grep -r "^#define __NR_" /usr/include/asm/unistd_64.h | head -20
# ็จ ausyscall ๆฅ่ฏข๏ผaudit ๅ
ๆไพ๏ผ
ausyscall --dump | grep -E "^(0|1|2|3|60)"
# ็ณป็ป่ฐ็จๆปๆฐ
grep -c "^#define __NR_" /usr/include/asm/unistd_64.h
# ๆฅ็ VDSO ๆ ๅฐ๏ผ/proc/self/maps ไธญ [vdso] ่ก๏ผ
cat /proc/self/maps | grep vdso
# 7fff12345000-7fff12346000 r-xp 00000000 00:00 0 [vdso]
2. strace Deep Dive
strace uses ptrace(2) to pause the target process at every kernel boundary, recording arguments and return values. Warning: strace slows the target process by 10โ100x. In production prefer -c summary mode or use bpftrace instead.
Common Options Quick Reference
| Option | Meaning |
|---|---|
| -p PID | Attach to running process |
| -tt | Show microsecond-precision absolute timestamps |
| -T | Show time spent in each call at end of line |
| -e trace=TYPE | Filter by category (file/network/process/signal/ipc/desc) |
| -e trace=open,read | Trace only specific call names |
| -c | Summary mode: count calls and total time (lowest overhead) |
| -f | Follow child processes created by fork/clone |
| -o FILE | Write output to file instead of stderr |
| -s 256 | String truncation length (default 32; increase to see full paths) |
| -y | Print fd numbers as file paths (more readable) |
# ๅบ็ก๏ผ่ท่ธชๆฐๅฏๅจๅฝไปค็ๆๆ็ณป็ป่ฐ็จ
strace ls /tmp
# ้ๅ ๅฐๅทฒๆ่ฟ็จ๏ผCtrl+C ๅๆญข๏ผไธๅฝฑๅ่ฟ็จ๏ผ
strace -p 1234
# ๆถ้ดๆณ + ่ๆถ๏ผๆๆฅๅฏๅจๆ
ข๏ผ
strace -tt -T -p 1234 2>&1 | head -50
# ๅช็ๆไปถ็ฑป่ฐ็จ๏ผopen/stat/read/write/close๏ผ
strace -e trace=file -p 1234
# ๅช็็ฝ็ป่ฐ็จ๏ผconnect/bind/accept/send/recv๏ผ
strace -e trace=network -p 1234
# ็ป่ฎกๆจกๅผโโ็ไบงๆๆฅๆจ่
strace -c -p 1234
# ๆ ทไพ่พๅบ๏ผ
# % time seconds usecs/call calls errors syscall
# ------- ----------- ----------- --------- --------- ----------------
# 52.13 0.002341 23 100 0 epoll_wait
# 21.30 0.000957 9 100 0 read
# 8.44 0.000379 7 54 12 openat
# 7.23 0.000325 3 90 0 write
# ่ท่ธชๅญ่ฟ็จ๏ผ-ff ๆฏไธชๅญ่ฟ็จๅ็ฌ็ซๆไปถ๏ผ
strace -f -o /tmp/strace.out nginx
# ๆๆฅ็จๅบๅฏๅจๆ
ข๏ผๆพๅคง้ stat() ่ฐ็จ
strace -tt -T -e trace=stat,statx,lstat ./slow_app 2>&1 | \
awk '{ sum += $NF; n++ } END { print n, "calls, total:", sum, "s" }'
# ๆๆฅๆไปถๆ้้ฎ้ข๏ผ็ openat ่ฟๅ็ EACCES/ENOENT
strace -e trace=openat -s 256 -y ./myapp 2>&1 | grep -E "EACCES|ENOENT"
# ๆๆฅ็ฝ็ป่ฟๆฅๅคฑ่ดฅ
strace -e trace=connect -p 1234 2>&1 | grep -E "ECONNREFUSED|ETIMEDOUT"
3. ltrace: Library Call Tracing
ltrace operates in user space, intercepting dynamic library function calls via PLT (Procedure Linkage Table) hooks โ no kernel entry required. It complements strace for analyzing malloc/free memory allocation, libc string operations, and other user-space behavior.
# ่ท่ธชๅจๆๅบ่ฐ็จ
ltrace ./myapp
# ้ๅ ๅฐ่ฟ่กไธญ่ฟ็จ
ltrace -p 1234
# ๅช่ท่ธชๅ
ๅญๅ้
๏ผๆๆฅๅ
ๅญๆณๆผ๏ผ
ltrace -e malloc,free,realloc,calloc -p 1234
# ็ป่ฎก่ฐ็จๆฌกๆฐไธ่ๆถ
ltrace -c ./myapp
# ๅๆถๆพ็คบ็ณป็ป่ฐ็จ๏ผ-S๏ผ
ltrace -S ./myapp
# ๆฅ็็จๅบ็ๅจๆๅบไพ่ต
ldd /usr/bin/curl
# ๅฏนๆฏ strace vs ltrace ็ๅ
ณ้ฎๅบๅซ
# strace: ๅ
ๆ ธๆ็ณป็ป่ฐ็จ๏ผread, write, open, fork...๏ผ
# ltrace: ็จๆทๆๅบๅฝๆฐ๏ผprintf, malloc, strcmp, fopen...๏ผ
# ๅปบ่ฎฎๆต็จ๏ผๅ
strace ็ๅ
ๆ ธๅฑ๏ผๅ ltrace ็ๅบๅฑ
4. /proc Virtual Filesystem
/proc is a read-only (partially writable) virtual filesystem where the kernel exports runtime state. It is mounted in memory and uses no disk space. Each process has a /proc/PID/ directory; kernel-global information lives in top-level files like /proc/sys/.
Per-Process Directory /proc/PID/
| Path | Contents | Common Use |
|---|---|---|
| cmdline | Full command line (NUL-separated) | cat /proc/1234/cmdline |
| maps | Memory map regions (address/perms/file) | See loaded .so libraries |
| smaps | Detailed RSS/PSS/Shared stats per segment | Precise memory usage analysis |
| fd/ | All open fds (symlinks to actual files) | ls -la /proc/1234/fd |
| fdinfo/ | Offset and flags for each fd | Debug fd state |
| status | Process status summary (VmRSS/Threads/State/PPid) | grep VmRSS /proc/1234/status |
| stat | Machine-readable process stats (source for ps) | Script-parse process data |
| environ | Environment variables at launch (NUL-separated) | cat /proc/1234/environ |
| cgroup | cgroup hierarchy path for this process | Confirm container membership |
| net/tcp | TCP socket table for this process | See listening ports |
# ๆฅ็่ฟ็จๅฝไปค่ก
cat /proc/1234/cmdline | tr '\0' ' '; echo
# ็ป่ฎก่ฟ็จๆๅผ็ๆไปถๆ่ฟฐ็ฌฆๆฐ้
ls /proc/1234/fd | wc -l
# ๆฅ็ๆฏไธช fd ๆๅ็ๆไปถ
ls -la /proc/1234/fd
# ๆฅ็ๅ
ๅญๅ ็จ๏ผVmRSS = ๅฎ้
็ฉ็ๅ
ๅญ๏ผ
grep -E "^(VmRSS|VmSize|VmSwap|Threads)" /proc/1234/status
# smaps_rollup: ๅฟซ้ๆฑๆป๏ผๅ
ๆ ธ 4.14+๏ผ
cat /proc/1234/smaps_rollup
# ๆฅ็็ฏๅขๅ้
cat /proc/1234/environ | tr '\0' '\n' | grep PATH
# /proc/self ๆฏๅฝๅ shell ็ๅฟซๆทๆนๅผ
cat /proc/self/status | head -10
# ้่ฟ maps ๆพๆๆๅ ่ฝฝ็ๅ
ฑไบซๅบ
grep "\.so" /proc/1234/maps | awk '{print $6}' | sort -u
Global /proc Files
# ๅ
ๅญๆฆ่ฆ
cat /proc/meminfo
# CPU ไฟกๆฏ๏ผๅๅทใๆ ธๆฐใ้ข็ใ็ผๅญ๏ผ
cat /proc/cpuinfo | grep -E "model name|cpu cores|cache size" | head -6
# ็ณป็ป่ด่ฝฝ๏ผ1/5/15ๅ้ๅๅผ๏ผ่ฟ่ก/ๆป่ฟ็จๆฐ๏ผๆ่ฟPID๏ผ
cat /proc/loadavg
# TCP ่ฟๆฅ่กจ๏ผๅๅ
ญ่ฟๅถๅฐๅ๏ผ้่ฝฌๆข๏ผ
cat /proc/net/tcp
# ไธญๆญ็ป่ฎก๏ผๆฏไธช CPU ็ไธญๆญๆฌกๆฐ๏ผ
cat /proc/interrupts | head -20
# ๅ
ๆ ธๅฏๅจๅๆฐ
cat /proc/cmdline
# ๆ่ฝฝไฟกๆฏ
cat /proc/mounts
# ๆไปถ็ณป็ปไฝฟ็จ้้ข
cat /proc/sys/fs/file-nr # ๅทฒ็จ/็ฉบ้ฒ/ๆๅคง fd ๆฐ
# /proc/sys ็ญๅ sysctl ๆฅๅฃ๏ผๅฏ็ดๆฅ่ฏปๅ๏ผ
cat /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward # ไธดๆถๅผๅฏ่ทฏ็ฑ่ฝฌๅ
5. sysctl: Kernel Parameter Tuning
sysctl provides a unified interface to read and write kernel parameters under /proc/sys/. Parameters are hierarchical: net.ipv4.tcp_syncookies maps to /proc/sys/net/ipv4/tcp_syncookies. Changes can be temporary (immediate but lost on reboot) or permanent (written to config files).
# ๆฅ็ๆๆๅๆฐ
sysctl -a
# ๆฅ็ๅไธชๅๆฐ
sysctl net.ipv4.tcp_max_syn_backlog
sysctl vm.swappiness
# ไธดๆถไฟฎๆน๏ผ้ๅฏๅๆขๅค้ป่ฎคๅผ๏ผ
sysctl -w net.ipv4.ip_forward=1
sysctl -w fs.file-max=1048576
# ๆฐธไน
ไฟฎๆน๏ผๅๅ
ฅ้
็ฝฎๆไปถ๏ผๆจ่็จ /etc/sysctl.d/๏ผ
cat > /etc/sysctl.d/99-production.conf
## 6. /sys Device Tree (sysfs)
sysfs is mounted at `/sys` and exports kernel objects (devices, drivers, buses) to user space as a directory tree. Compared to /proc, sysfs enforces a stricter "one directory per object, one file per attribute" structure and is the foundation for udev rules and hardware management.
```bash
# ้กถๅฑ็ปๆ
ls /sys/
# block bus class dev devices firmware fs kernel module power
# ๆฅ็ๆๆๅ่ฎพๅค
ls /sys/block/
# ็ฃ็ sda ็ไฟกๆฏ
cat /sys/block/sda/size # ๆปๆๅบๆฐ
cat /sys/block/sda/queue/rotational # 0=SSD๏ผ1=HDD
cat /sys/block/sda/queue/scheduler # IO ่ฐๅบฆๅจ
cat /sys/block/sda/device/model # ็กฌ็ๅๅท
# ็ฝ็ปๆฅๅฃไฟกๆฏ
cat /sys/class/net/eth0/speed # ้็ (Mbps)
cat /sys/class/net/eth0/operstate # up/down
cat /sys/class/net/eth0/statistics/rx_bytes # ๆฅๆถๅญ่ๆฐ
# CPU ้ข็ไธ็็ต
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# ไฟฎๆน CPU ๆง่ฝๆจกๅผ๏ผ้ root๏ผ
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# ่ฐๆด IO ่ฐๅบฆๅจ๏ผๅฏน SSD ๆจ่ none ๆ mq-deadline๏ผ
echo mq-deadline > /sys/block/nvme0n1/queue/scheduler
# udev ่งๅ๏ผ่ชๅจๅ ่ฝฝ้ฉฑๅจใๅฝๅ่ฎพๅค็ญ๏ผ
ls /etc/udev/rules.d/
# udevadm info ๆฅ็่ฎพๅคๅฑๆง๏ผ็จไบ็ผๅ่งๅ๏ผ
udevadm info --query=all --name=/dev/sda | head -20
# debugfs๏ผ้ root๏ผๆ่ฝฝ่ฐ่ฏๆฅๅฃ๏ผ
mount -t debugfs none /sys/kernel/debug
ls /sys/kernel/debug/tracing/ # ftrace ๆฅๅฃ
7. Kernel Modules
Kernel modules (.ko files) are dynamically loadable/unloadable kernel code segments โ no kernel recompilation or reboot required. Drivers, filesystems, and network protocols exist as modules. Loaded modules run in Ring 0; a crash will cause a kernel panic.
Module Management Commands
# ๆฅ็ๅทฒๅ ่ฝฝๆจกๅ๏ผๅ็งฐ/ๅคงๅฐ/ไพ่ตๆฐ/ไพ่ต่
๏ผ
lsmod
# ๆฅ็ๆจกๅ่ฏฆ็ปไฟกๆฏ๏ผ็ๆฌ/ๅๆฐ/ไพ่ต/ๆ่ฟฐ๏ผ
modinfo ext4
modinfo nvidia
# ๅ ่ฝฝๆจกๅๅๅ
ถๆๆไพ่ต๏ผๆจ่๏ผ
modprobe nf_conntrack
# ๅ ่ฝฝๆจกๅๅนถไผ ้ๅๆฐ
modprobe usbhid quirks=0x1234:0x5678:0x0004
# ๅธ่ฝฝๆจกๅ๏ผๅฆๆๆ ่ฟ็จไฝฟ็จ๏ผ
modprobe -r nf_conntrack
# ็ดๆฅๅ ่ฝฝ .ko ๆไปถ๏ผไธ่งฃๆไพ่ต๏ผ่ฐ่ฏไธ็จ๏ผ
insmod /path/to/mymodule.ko
# ็ดๆฅๅธ่ฝฝ๏ผไธๆฃๆฅไพ่ต๏ผๆ
็จ๏ผ
rmmod mymodule
# ๆฅ็ๆจกๅๅๆฐ
cat /sys/module/ext4/parameters/
ls /sys/module/nf_conntrack/parameters/
# ๅผๆบ่ชๅจๅ ่ฝฝ้
็ฝฎ
cat /etc/modules-load.d/modules.conf
echo "nf_conntrack" >> /etc/modules-load.d/custom.conf
# ๆจกๅๅๆฐๆไน
ๅ้
็ฝฎ
cat > /etc/modprobe.d/custom.conf
## 8. dmesg: Kernel Log
dmesg reads the kernel's ring buffer log, which contains hardware detection, driver messages, kernel warnings, and errors. After boot, logs are saved to `/var/log/kern.log` (rsyslog) or accessed via `journalctl -k` (systemd).
```bash
# ๆพ็คบๆๆๅ
ๆ ธๆฅๅฟ๏ผๅธฆไบบ็ฑปๅฏ่ฏปๆถ้ดๆณ๏ผ
dmesg -T
# ๅช็่ญฆๅๅ้่ฏฏ
dmesg -T -l warn,err
# ๅช็็นๅฎ่ฎพๆฝ๏ผkern=ๅ
ๆ ธ๏ผuser=็จๆทๆ๏ผdaemon=ๅฎๆค่ฟ็จ๏ผ
dmesg -T -f kern
# ๅฎๆถ่ท่ธช๏ผ็ฑปไผผ tail -f๏ผๅ
ๆ ธ 3.5+๏ผ
dmesg --follow
# ่ฟๆปคๅ
ณ้ฎๅญ
dmesg -T | grep -i "oom\|killed\|out of memory"
dmesg -T | grep -i "error\|fail\|hardware"
dmesg -T | grep -i "sda\|nvme\|I/O error"
# ๆธ
้ค ring buffer๏ผๆ
็จ๏ผ้ root๏ผ
dmesg -C
# ๅธธ่งๅ
ๆ ธ้่ฏฏ่งฃ่ฏป๏ผ
# OOM killer๏ผๅ
ๅญไธ่ถณ๏ผๅ
ๆ ธๅผบๆ่ฟ็จ๏ผ
# Out of memory: Killed process 1234 (java) total-vm:4096kB, anon-rss:2048kB
# โ ่งฃๅณ๏ผๅขๅ ๅ
ๅญ๏ผ่ฐๆด vm.swappiness๏ผๆ้ๅถ่ฟ็จๅ
ๅญ็จ้
# ็กฌไปถ้่ฏฏ๏ผ็ฃ็ๅๅ๏ผ
# end_request: I/O error, dev sda, sector 1234567
# blk_update_request: I/O error, dev sda, sector 1234567 op 0x0:(READ)
# โ ่งฃๅณ๏ผsmartctl -a /dev/sda ๆฃๆฅ SMART ็ถๆ๏ผๅฐฝๅฟซๅคไปฝ่ฟ็งปๆฐๆฎ
# ็ฝ็ป่ฎพๅคไธขๅ
# eth0: Dropped oversize packet
# eth0: RX ring buffer not full
# โ ่งฃๅณ๏ผๅขๅคง /proc/sys/net/core/netdev_max_backlog
# ๆไปถ็ณป็ป้่ฏฏ
# EXT4-fs error (device sda1): ext4_find_entry:1455: inode #2: comm bash
# โ ่งฃๅณ๏ผumount ๅ fsck -y /dev/sda1
# ็ณป็ปๆฅๅฟ๏ผjournalctl๏ผ
journalctl -k # ๆฌๆฌกๅฏๅจ็ๅ
ๆ ธๆฅๅฟ
journalctl -k -b -1 # ไธๆฌกๅฏๅจ็ๅ
ๆ ธๆฅๅฟ
journalctl -k -p err # ๅช็ๅ
ๆ ธ้่ฏฏ็บงๅซ
journalctl -k --since "1 hour ago" # ๆ่ฟ1ๅฐๆถๅ
ๆ ธๆฅๅฟ
9. Kernel Debug Interfaces
SysRq
The SysRq key (Magic System Request Key) provides emergency direct-kernel control, potentially responsive even when the system appears frozen. Trigger from scripts via /proc/sysrq-trigger.
# ๅฏ็จ SysRq๏ผๅผ 1=ๅ
จ้จๅฏ็จ๏ผ438=้ๆฉๆงๅฏ็จ๏ผ
echo 1 > /proc/sys/kernel/sysrq
# ่งฆๅๆไฝ๏ผๅๅ
ฅ /proc/sysrq-trigger๏ผ
echo m > /proc/sysrq-trigger # ๆๅฐๅ
ๅญไฟกๆฏๅฐ dmesg
echo t > /proc/sysrq-trigger # ๆๅฐๆๆ็บฟ็จ็ถๆ
echo b > /proc/sysrq-trigger # ็ซๅณ้ๅฏ๏ผไธๅไปปไฝๆธ
็๏ผ๏ผ
echo s > /proc/sysrq-trigger # sync ๆๆๆไปถ็ณป็ป
echo u > /proc/sysrq-trigger # ไปฅๅช่ฏป้ๆฐๆ่ฝฝๆๆๆไปถ็ณป็ป
# ๅฎๅ
จ้ๅฏ๏ผsync + unmount + reboot๏ผ๏ผไพๆฌกๆ s u b
echo s > /proc/sysrq-trigger; sync
echo u > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger
ftrace
ftrace is the kernel's built-in function tracer, exposed via debugfs. It can trace any kernel function call with extremely low overhead.
# ๆ่ฝฝ debugfs๏ผ้ๅธธๅทฒ่ชๅจๆ่ฝฝ๏ผ
mount -t debugfs none /sys/kernel/debug
cd /sys/kernel/debug/tracing
# ๆฅ็ๅฏ็จ tracer
cat available_tracers
# blk function function_graph wakeup nop
# ไฝฟ็จๅฝๆฐๅพ tracer๏ผ่ฟฝ่ธชๅฝๆฐ่ฐ็จๆ ๏ผ
echo function_graph > current_tracer
# ๅช่ฟฝ่ธช็นๅฎๅฝๆฐ
echo do_sys_open > set_ftrace_filter
# ๅผๅง่ฟฝ่ธช
echo 1 > tracing_on
# ๆฅ็็ปๆ
cat trace | head -50
# ๅๆญข่ฟฝ่ธช
echo 0 > tracing_on
echo nop > current_tracer
10. Practice: Investigating a File Descriptor Leak
Production scenario: a web service starts throwing "Too many open files" errors after running for a while, and HTTP requests begin failing. Here is the complete investigation chain:
## ๆญฅ้ชค1๏ผ็กฎ่ฎค็ฐ่ฑกโโๆพๅฐ่ฟ็จ PID
systemctl status mywebapp
# ่ทๅพ PID๏ผๅ่ฎพไธบ 2341
## ๆญฅ้ชค2๏ผๆฅ็่ฟ็จๅฝๅ fd ๆฐ้
ls /proc/2341/fd | wc -l
# ่พๅบ๏ผ65530 โ ๆฅ่ฟ็ณป็ป้ป่ฎค้ๅถ 65536
## ๆญฅ้ชค3๏ผๆฅ็่ฟ็จ fd ้ๅถ๏ผsoft limit๏ผ
cat /proc/2341/limits | grep "open files"
# Max open files 65536 65536 files
## ๆญฅ้ชค4๏ผๅๆ fd ็ฑปๅๅๅธ
ls -la /proc/2341/fd | awk '{print $NF}' | \
sed 's|/proc.*||' | sort | uniq -c | sort -rn | head -20
# ๅ็ฐๅคง้ /tmp/upload-XXXXXX ไธดๆถๆไปถๆก็ฎ
## ๆญฅ้ชค5๏ผ็จ strace ็กฎ่ฎคโโๆฏๅฆๆๅช open ไธ close
strace -e trace=openat,close -c -p 2341
# ็ป่ฎกๆจกๅผ่พๅบ๏ผ
# calls: openat=1000, close=10 โ open/close ไธฅ้ไธๅนณ่กก
## ๆญฅ้ชค6๏ผlsof ๆฅ็ๅ
ทไฝๆณๆผๆไปถ
lsof -p 2341 | grep "/tmp/upload" | head -20
# ๅ็ฐๅคง้ไธไผ ไธดๆถๆไปถ fd ๆชๅ
ณ้ญ
## ๆญฅ้ชค7๏ผsysctl ๆฅ็็ณป็ป็บง fd ไฝฟ็จๆ
ๅต
cat /proc/sys/fs/file-nr
# ๅทฒ็จ/็ฉบ้ฒ/ๆๅคง๏ผ800000 0 1048576
## ๆญฅ้ชค8๏ผไธดๆถ็ผ่งฃโโๆๅ้ๅถ๏ผไธไฟฎๅคๆ นๅ ๏ผไป
ไบๅๆถ้ด๏ผ
# /etc/security/limits.conf ๆ systemd service ็ LimitNOFILE
cat >> /etc/security/limits.d/mywebapp.conf 50000 ๅ่ญฆ
Investigation Summary: File descriptor leak investigation path: /proc/PID/fd count โ limits check โ strace -c unbalanced open/close โ lsof file identification โ /proc/sys/fs/file-nr system view โ code fix โ monitoring alert. Core tool combination:
/proc+strace+lsof+sysctl, covering the full chain from kernel to code.
Previous
โ Ch16: Containers
Next
Ch18: Mini Shell โ