Open11

「試して理解 Linuxのしくみ」の読書録

yuji38kwmtyuji38kwmt

https://gihyo.jp/book/2018/978-4-7741-9607-7

正誤表

https://github.com/satoru-takeuchi/linux-in-practice

実行環境

  • Thinkpad X220
  • XUbuntu 20.04
$ uname -a
Linux yuji-ThinkPad-X220 5.4.0-121-generic #137-Ubuntu SMP Wed Jun 15 13:33:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
yuji@yuji-ThinkPad-X220:~$ 

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.4 LTS
Release:	20.04
Codename:	focal

$  sudo lshw -class processor
[sudo] yuji のパスワード: 
  *-cpu                     
       詳細: CPU
       製品: Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
       ベンダー: Intel Corp.
       物理ID: 1
       バス情報: cpu@0
       バージョン: Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
       シリアル: Not Supported by CPU
       スロット: CPU
       サイズ: 974MHz
       容量: 3500MHz
       幅: 64 bits
       クロック: 100MHz
       性能: lm fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx rdtscp x86-64 constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts md_clear flush_l1d cpufreq
       設定: cores=2 enabledcores=2 threads=4


$ sudo lshw

    *-memory
          詳細: システムメモリー
          物理ID: 5
          スロット: システムボードまたはマザーボード
          サイズ: 8GiB
        *-bank:0
             詳細: SODIMM DDR3 同期 1333 MHz (0.8 ns)
             製品: M471B5273DH0-CH9
             ベンダー: Samsung
             物理ID: 0
             シリアル: xxx
             スロット: ChannelA-DIMM0
             サイズ: 4GiB
             幅: 64 bits
             クロック: 1333MHz (0.8ns)
        *-bank:1
             詳細: SODIMM DDR3 同期 1333 MHz (0.8 ns)
             製品: HYF3A1C167HZ3
             ベンダー: Fujitsu
             物理ID: 1
             シリアル: xxx
             スロット: ChannelB-DIMM0
             サイズ: 4GiB
             幅: 64 bits
             クロック: 1333MHz (0.8ns)




     *-scsi
          物理ID: 8
          論理名: scsi0
          性能: emulated
        *-disk
             詳細: ATA Disk
             製品: HITACHI HTS54323
             ベンダー: Hitachi
             物理ID: 0.0.0
             バス情報: scsi@0:0.0.0
             論理名: /dev/sda
             バージョン: B70T
             シリアル: xxx
             サイズ: 298GiB (320GB)
             性能: partitioned partitioned:dos
             設定: ansiversion=5 logicalsectorsize=512 sectorsize=512 signature=64e8f38e
           *-volume:0
                詳細: EXT4ボリューム
                ベンダー: Linux
                物理ID: 1
                バス情報: scsi@0:0.0.0,1
                論理名: /dev/sda1
                論理名: /
                バージョン: 1.0
                シリアル: xxx
                サイズ: 290GiB
                容量: 290GiB
                性能: primary bootable journaled extended_attributes large_files huge_files dir_nlink extents ext4 ext2 initialized
                設定: created=2022-06-30 08:20:43 filesystem=ext4 lastmountpoint=/ modified=2022-07-10 22:21:05 mount.fstype=ext4 mount.options=rw,relatime,errors=remount-ro mounted=2022-07-10 15:26:09 state=mounted
           *-volume:1
                詳細: Extended partition
                物理ID: 2
                バス情報: scsi@0:0.0.0,2
                論理名: /dev/sda2
                サイズ: 8074MiB
                容量: 8074MiB
                性能: primary extended partitioned partitioned:extended
              *-logicalvolume
                   詳細: Linux swap ボリューム
                   物理ID: 5
                   論理名: /dev/sda5
                   バージョン: 1
                   シリアル: xxx
                   サイズ: 8074MiB
                   容量: 8074MiB
                   性能: nofs swap initialized
                   設定: filesystem=swap pagesize=4096

yuji38kwmtyuji38kwmt

2章

システムコールの呼び出し

hello.cのシステムコール

$ cat hello.log
execve("./hello", ["./hello"], 0x7ffd860dbe80 /* 53 vars */) = 0
brk(NULL)                               = 0x55cec6926000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe6d1b5c50) = -1 EINVAL (無効な引数です)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (そのようなファイルやディレクトリはありません)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=84453, ...}) = 0
mmap(NULL, 84453, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f09546e0000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f09546de000
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f09544ec000
mmap(0x7f095450e000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7f095450e000
mmap(0x7f0954686000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7f0954686000
mmap(0x7f09546d4000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f09546d4000
mmap(0x7f09546da000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f09546da000
close(3)                                = 0
arch_prctl(ARCH_SET_FS, 0x7f09546df540) = 0
mprotect(0x7f09546d4000, 16384, PROT_READ) = 0
mprotect(0x55cec4acb000, 4096, PROT_READ) = 0
mprotect(0x7f0954722000, 4096, PROT_READ) = 0
munmap(0x7f09546e0000, 84453)           = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x3), ...}) = 0
brk(NULL)                               = 0x55cec6926000
brk(0x55cec6947000)                     = 0x55cec6947000
write(1, "hello world\n", 12)           = 12
exit_group(0)                           = ?
+++ exited with 0 +++
yuji38kwmtyuji38kwmt

P16 hello.pyのシステムコール

$ strace -o hello.py.log python3 hello.py

$ wc -l hello.py.log 
519 hello.py.log
$ tail hello.py.log 
lseek(3, 0, SEEK_SET)                   = 0
read(3, "print(\"hello world\")\n", 4096) = 21
read(3, "", 4096)                       = 0
close(3)                                = 0
write(1, "hello world\n", 12)           = 12
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7ffa37770090}, {sa_handler=0x6290b0, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7ffa37770090}, 8) = 0
sigaltstack(NULL, {ss_sp=0x20e1440, ss_flags=0, ss_size=16384}) = 0
sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}, NULL) = 0
exit_group(0)                           = ?
+++ exited with 0 +++


yuji38kwmtyuji38kwmt

loop.cの実行中の統計情報

yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/02-syscall-and-non-kernel-os$ ./loop & 
[1] 4264
yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/02-syscall-and-non-kernel-os$ sar -P ALL 1 
Linux 5.4.0-121-generic (yuji-ThinkPad-X220) 	2022年07月10日 	_x86_64_	(4 CPU)

22時57分23秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
22時57分24秒     all     25.25      0.00      0.25      0.00      0.00     74.50
22時57分24秒       0      0.99      0.00      0.99      0.00      0.00     98.02
22時57分24秒       1      0.00      0.00      0.00      0.00      0.00    100.00
22時57分24秒       2    100.00      0.00      0.00      0.00      0.00      0.00
22時57分24秒       3      0.00      0.00      0.00      0.00      0.00    100.00

22時57分24秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
22時57分25秒     all     25.00      0.00      0.00      0.00      0.00     75.00
22時57分25秒       0      0.00      0.00      0.00      0.00      0.00    100.00
22時57分25秒       1      0.00      0.00      0.00      0.00      0.00    100.00
22時57分25秒       2    100.00      0.00      0.00      0.00      0.00      0.00
22時57分25秒       3      0.00      0.00      0.00      0.00      0.00    100.00

ppidloop.cの統計情報

yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/02-syscall-and-non-kernel-os$ ./ppiidloop &
[1] 4348
yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/02-syscall-and-non-kernel-os$ sar -P ALL 1 
Linux 5.4.0-121-generic (yuji-ThinkPad-X220) 	2022年07月10日 	_x86_64_	(4 CPU)

23時01分40秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時01分41秒     all     14.93      0.00     10.95      0.00      0.00     74.13
23時01分41秒       0      0.98      0.00      0.98      0.00      0.00     98.04
23時01分41秒       1      0.00      0.00      1.00      0.00      0.00     99.00
23時01分41秒       2     58.00      0.00     42.00      0.00      0.00      0.00
23時01分41秒       3      1.00      0.00      0.00      0.00      0.00     99.00

23時01分41秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
23時01分42秒     all     14.79      0.00     10.53      0.00      0.00     74.69
23時01分42秒       0      0.00      0.00      0.00      0.00      0.00    100.00
23時01分42秒       1      0.00      0.00      0.00      0.00      0.00    100.00
23時01分42秒       2     58.00      0.00     42.00      0.00      0.00      0.00
23時01分42秒       3      1.00      0.00      0.00      0.00      0.00     99.00

yuji38kwmtyuji38kwmt

システムコール所要時間

$ strace -T  ./hello
execve("./hello", ["./hello"], 0x7fffc3d420b8 /* 53 vars */) = 0 <0.000616>
brk(NULL)                               = 0x563869102000 <0.000042>
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc1852c8f0) = -1 EINVAL (無効な引数です) <0.000062>
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (そのようなファイルやディレクトリはありません) <0.000017>
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 <0.000016>
fstat(3, {st_mode=S_IFREG|0644, st_size=84453, ...}) = 0 <0.000011>
mmap(NULL, 84453, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fe851e55000 <0.000013>
close(3)                                = 0 <0.000007>
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 <0.000010>
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300A\2\0\0\0\0\0"..., 832) = 832 <0.000008>
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 <0.000007>
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32 <0.000007>
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68 <0.000007>
fstat(3, {st_mode=S_IFREG|0755, st_size=2029592, ...}) = 0 <0.000007>
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe851e53000 <0.000008>
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 <0.000007>
pread64(3, "\4\0\0\0\20\0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0", 32, 848) = 32 <0.000007>
pread64(3, "\4\0\0\0\24\0\0\0\3\0\0\0GNU\0\30x\346\264ur\f|Q\226\236i\253-'o"..., 68, 880) = 68 <0.000007>
mmap(NULL, 2037344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fe851c61000 <0.000008>
mmap(0x7fe851c83000, 1540096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7fe851c83000 <0.000015>
mmap(0x7fe851dfb000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19a000) = 0x7fe851dfb000 <0.000012>
mmap(0x7fe851e49000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7fe851e49000 <0.000012>
mmap(0x7fe851e4f000, 13920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fe851e4f000 <0.000011>
close(3)                                = 0 <0.000007>
arch_prctl(ARCH_SET_FS, 0x7fe851e54540) = 0 <0.000008>
mprotect(0x7fe851e49000, 16384, PROT_READ) = 0 <0.000011>
mprotect(0x563868bb6000, 4096, PROT_READ) = 0 <0.000009>
mprotect(0x7fe851e97000, 4096, PROT_READ) = 0 <0.000009>
munmap(0x7fe851e55000, 84453)           = 0 <0.000021>
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0 <0.000007>
brk(NULL)                               = 0x563869102000 <0.000007>
brk(0x563869123000)                     = 0x563869123000 <0.000008>
write(1, "hello world\n", 12hello world
)           = 12 <0.000012>
exit_group(0)                           = ?
+++ exited with 0 +++
yuji38kwmtyuji38kwmt

lddコマンドでどのライブラリをリンクしているか調べる

$ ldd /bin/echo
	linux-vdso.so.1 (0x00007ffc7b864000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f68ebcf5000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f68ebf09000)

$ ldd /usr/bin/python3
	linux-vdso.so.1 (0x00007ffe2ebcf000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f125f8cc000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f125f8a9000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f125f8a3000)
	libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f125f89e000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f125f74f000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f125f721000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f125f703000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f125fad5000)
yuji38kwmtyuji38kwmt

P34 エントリポイント

$ readelf -h /bin/sleep
ELF ヘッダ:
  マジック:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  クラス:                            ELF64
  データ:                            2 の補数、リトルエンディアン
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI バージョン:                    0
  型:                                DYN (共有オブジェクトファイル)
  マシン:                            Advanced Micro Devices X86-64
  バージョン:                        0x1
  エントリポイントアドレス:               0x2850
  プログラムヘッダ始点:          64 (バイト)
  セクションヘッダ始点:          37336 (バイト)
  フラグ:                            0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         13
  Size of section headers:           64 (bytes)
  Number of section headers:         30
  Section header string table index: 29
$ readelf -S /bin/sleep
There are 30 section headers, starting at offset 0x91d8:

セクションヘッダ:
  [番] 名前              タイプ           アドレス          オフセット
       サイズ            EntSize          フラグ Link  情報  整列
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000000318  00000318
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.gnu.propert NOTE             0000000000000338  00000338
       0000000000000020  0000000000000000   A       0     0     8
  [ 3] .note.gnu.build-i NOTE             0000000000000358  00000358
       0000000000000024  0000000000000000   A       0     0     4
  [ 4] .note.ABI-tag     NOTE             000000000000037c  0000037c
       0000000000000020  0000000000000000   A       0     0     4
  [ 5] .gnu.hash         GNU_HASH         00000000000003a0  000003a0
       00000000000000a8  0000000000000000   A       6     0     8
  [ 6] .dynsym           DYNSYM           0000000000000448  00000448
       0000000000000600  0000000000000018   A       7     1     8
  [ 7] .dynstr           STRTAB           0000000000000a48  00000a48
       000000000000031f  0000000000000000   A       0     0     1
  [ 8] .gnu.version      VERSYM           0000000000000d68  00000d68
       0000000000000080  0000000000000002   A       6     0     2
  [ 9] .gnu.version_r    VERNEED          0000000000000de8  00000de8
       0000000000000060  0000000000000000   A       7     1     8
  [10] .rela.dyn         RELA             0000000000000e48  00000e48
       00000000000002b8  0000000000000018   A       6     0     8
  [11] .rela.plt         RELA             0000000000001100  00001100
       00000000000003f0  0000000000000018  AI       6    25     8
  [12] .init             PROGBITS         0000000000002000  00002000
       000000000000001b  0000000000000000  AX       0     0     4
  [13] .plt              PROGBITS         0000000000002020  00002020
       00000000000002b0  0000000000000010  AX       0     0     16
  [14] .plt.got          PROGBITS         00000000000022d0  000022d0
       0000000000000010  0000000000000010  AX       0     0     16
  [15] .plt.sec          PROGBITS         00000000000022e0  000022e0
       00000000000002a0  0000000000000010  AX       0     0     16
  [16] .text             PROGBITS         0000000000002580  00002580
       0000000000003692  0000000000000000  AX       0     0     16
  [17] .fini             PROGBITS         0000000000005c14  00005c14
       000000000000000d  0000000000000000  AX       0     0     4
  [18] .rodata           PROGBITS         0000000000006000  00006000
       0000000000000f6c  0000000000000000   A       0     0     32
  [19] .eh_frame_hdr     PROGBITS         0000000000006f6c  00006f6c
       00000000000002b4  0000000000000000   A       0     0     4
  [20] .eh_frame         PROGBITS         0000000000007220  00007220
       0000000000000d18  0000000000000000   A       0     0     8
  [21] .init_array       INIT_ARRAY       0000000000009bb0  00008bb0
       0000000000000008  0000000000000008  WA       0     0     8
  [22] .fini_array       FINI_ARRAY       0000000000009bb8  00008bb8
       0000000000000008  0000000000000008  WA       0     0     8
  [23] .data.rel.ro      PROGBITS         0000000000009bc0  00008bc0
       00000000000000b8  0000000000000000  WA       0     0     32
  [24] .dynamic          DYNAMIC          0000000000009c78  00008c78
       00000000000001f0  0000000000000010  WA       7     0     8
  [25] .got              PROGBITS         0000000000009e68  00008e68
       0000000000000190  0000000000000008  WA       0     0     8
  [26] .data             PROGBITS         000000000000a000  00009000
       0000000000000080  0000000000000000  WA       0     0     32
  [27] .bss              NOBITS           000000000000a080  00009080
       00000000000001b8  0000000000000000  WA       0     0     32
  [28] .gnu_debuglink    PROGBITS         0000000000000000  00009080
       0000000000000034  0000000000000000           0     0     4
  [29] .shstrtab         STRTAB           0000000000000000  000090b4
       000000000000011d  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  l (large), p (processor specific)
yuji@yuji-ThinkPad-X220:~$ /bin/sleep 10000 &
[1] 2060
yuji@yuji-ThinkPad-X220:~$ cat /proc/2060/maps
55ab8b13e000-55ab8b140000 r--p 00000000 08:01 3408056                    /bin/sleep
55ab8b140000-55ab8b144000 r-xp 00002000 08:01 3408056                    /bin/sleep
55ab8b144000-55ab8b146000 r--p 00006000 08:01 3408056                    /bin/sleep
55ab8b147000-55ab8b148000 r--p 00008000 08:01 3408056                    /bin/sleep
55ab8b148000-55ab8b149000 rw-p 00009000 08:01 3408056                    /bin/sleep
55ab8b6f7000-55ab8b718000 rw-p 00000000 00:00 0                          [heap]
7f422607e000-7f42266f1000 r--p 00000000 08:01 14418418                   /usr/lib/locale/locale-archive
7f42266f1000-7f4226713000 r--p 00000000 08:01 13631590                   /lib/x86_64-linux-gnu/libc-2.31.so
7f4226713000-7f422688b000 r-xp 00022000 08:01 13631590                   /lib/x86_64-linux-gnu/libc-2.31.so
7f422688b000-7f42268d9000 r--p 0019a000 08:01 13631590                   /lib/x86_64-linux-gnu/libc-2.31.so
7f42268d9000-7f42268dd000 r--p 001e7000 08:01 13631590                   /lib/x86_64-linux-gnu/libc-2.31.so
7f42268dd000-7f42268df000 rw-p 001eb000 08:01 13631590                   /lib/x86_64-linux-gnu/libc-2.31.so
7f42268df000-7f42268e5000 rw-p 00000000 00:00 0 
7f42268fa000-7f42268fb000 r--p 00000000 08:01 13631515                   /lib/x86_64-linux-gnu/ld-2.31.so
7f42268fb000-7f422691e000 r-xp 00001000 08:01 13631515                   /lib/x86_64-linux-gnu/ld-2.31.so
7f422691e000-7f4226926000 r--p 00024000 08:01 13631515                   /lib/x86_64-linux-gnu/ld-2.31.so
7f4226927000-7f4226928000 r--p 0002c000 08:01 13631515                   /lib/x86_64-linux-gnu/ld-2.31.so
7f4226928000-7f4226929000 rw-p 0002d000 08:01 13631515                   /lib/x86_64-linux-gnu/ld-2.31.so
7f4226929000-7f422692a000 rw-p 00000000 00:00 0 
7fff27c6d000-7fff27c8e000 rw-p 00000000 00:00 0                          [stack]
7fff27d84000-7fff27d87000 r--p 00000000 00:00 0                          [vvar]
7fff27d87000-7fff27d88000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0                  [vsyscall]
yuji38kwmtyuji38kwmt
	char *args[] = { "/bin/echo", "hello" , NULL};
	execve("/bin/echo", args, NULL);

なぜ argsの先頭に/bin/echoが必要?

yuji38kwmtyuji38kwmt

https://linuxjm.osdn.jp/html/procps/man1/ps.1.html

$ sar -q 1 1
Linux 5.4.0-121-generic (yuji-ThinkPad-X220) 	2022年07月17日 	_x86_64_	(4 CPU)

07時16分46秒   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked
07時16分47秒         1       685      0.82      0.39      0.29         0
平均値:          1       685      0.82      0.39      0.29         0

経過時間と使用時間

yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/04-process-scheduler$ time taskset -c 0 ./sched 1 10000 10000
estimating the workload which takes just one milli-second...
end estimation
0	10412	100

real	0m12.691s
user	0m12.686s
sys	0m0.001s
yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/04-process-scheduler$ time taskset -c 0 ./sched 2 10000 10000
estimating the workload which takes just one milli-second...
end estimation
1	21507	100
0	21513	100

real	0m23.787s
user	0m23.780s
sys	0m0.001s
yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/04-process-scheduler$ time taskset -c 0,1 ./sched 1 10000 10000
estimating the workload which takes just one milli-second...
end estimation
0	10762	100

real	0m13.043s
user	0m13.035s
sys	0m0.004s
yuji@yuji-ThinkPad-X220:~/Documents/study/linux-in-practice/04-process-scheduler$ time taskset -c 0,1 ./sched 2 10000 10000
estimating the workload which takes just one milli-second...
end estimation
0	12943	100
1	13000	100

real	0m15.284s
user	0m28.214s
sys	0m0.004s