KDOC 107: システムコールを調べる

この文書のステータス

  • 作成
    • 2024-02-26 貴島
  • レビュー
    • 2024-03-17 貴島

概要

システムプログラミングを理解していくうえで、システムコールがどういったものかを理解しようとしている。調べる方法を書く。

調べる方法

セクション番号を調べる。

man -k read | grep "2" | head -n 30
_llseek (2)          - reposition read/write file offset
_sysctl (2)          - read/write system parameters
arch_prctl (2)       - set architecture-specific thread state
capget (2)           - set/get capabilities of thread(s)
capset (2)           - set/get capabilities of thread(s)
exit_group (2)       - exit all threads in a process
file2brl (1)         - Translate an xml or a text file into an embosser-ready...
get_mempolicy (2)    - retrieve NUMA memory policy for a thread
get_thread_area (2)  - manipulate thread-local storage information
getcpu (2)           - determine CPU and NUMA node on which the calling threa...
gettid (2)           - get thread identification
io_getevents (2)     - read asynchronous I/O events from the completion queue
llseek (2)           - reposition read/write file offset
lseek (2)            - reposition read/write file offset
membarrier (2)       - issue memory barriers on a set of threads
pciconfig_read (2)   - pci device information handling
prctl (2)            - operations on a process or thread
pread (2)            - read from or write to a file descriptor at a given offset
pread64 (2)          - read from or write to a file descriptor at a given offset
preadv (2)           - read or write data into multiple buffers
preadv2 (2)          - read or write data into multiple buffers
process_vm_readv (2) - transfer data between process address spaces
pwrite (2)           - read from or write to a file descriptor at a given offset
pwrite64 (2)         - read from or write to a file descriptor at a given offset
pwritev (2)          - read or write data into multiple buffers
pwritev2 (2)         - read or write data into multiple buffers
read (2)             - read from a file descriptor
readahead (2)        - initiate file readahead into page cache
readdir (2)          - read directory entry
readlink (2)         - read value of a symbolic link

関数名のあとのカッコの番号がセクション番号。セクション番号1は実行可能コマンド。セクション番号2であればシステムコール。

セクション番号によってシステムコールを特定できたら、該当ページを見る。↓readの例。

man -a read | head -n 20
READ(2)                    Linux Programmer's Manual                   READ(2)

NAME
       read - read from a file descriptor

SYNOPSIS
       #include <unistd.h>

       ssize_t read(int fd, void *buf, size_t count);

DESCRIPTION
       read()  attempts to read up to count bytes from file descriptor fd into
       the buffer starting at buf.

       On files that support seeking, the read operation commences at the file
       offset, and the file offset is incremented by the number of bytes read.
       If the file offset is at or past the end of file, no  bytes  are  read,
       and read() returns zero.

       If count is zero, read() may detect the errors described below.  In the

関連