OSDN Git Service

c415defce1636d03c981a9d547db1b6b44480026
[linuxjm/LDP_man-pages.git] / draft / man5 / core.5
1 .\" Copyright (c) 2006, 2008 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Japanese Version Copyright (c) 2006-2008 Akihiro MOTOKI
24 .\" Translated 2006-04-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
25 .\" Updated 2007-01-05, Akihiro MOTOKI, LDP v2.43
26 .\" Updated 2007-09-03, Akihiro MOTOKI, LDP v2.64
27 .\" Updated 2008-08-10, Akihiro MOTOKI, LDP v3.05
28 .\" Updated 2008-09-19, Akihiro MOTOKI, LDP v3.08
29 .\"
30 .TH CORE 5 2010-11-15 "Linux" "Linux Programmer's Manual"
31 .\"O .SH NAME
32 .SH 名前
33 .\"O core \- core dump file
34 core \- コアダンプファイル
35 .\"O .SH DESCRIPTION
36 .SH 説明
37 .\"O The default action of certain signals is to cause a process to terminate 
38 .\"O and produce a
39 .\"O .IR "core dump file" ,
40 .\"O a disk file containing an image of the process's memory at 
41 .\"O the time of termination.
42 .\"O This image can be used in a debugger (e.g.,
43 .\"O .BR gdb (1))
44 .\"O to inspect the state of the program at the time that it terminated.
45 .\"O A list of the signals which cause a process to dump core can be found in
46 .\"O .BR signal (7).
47 ある種のシグナルを受けた場合のデフォルトのアクションは、
48 プロセスを終了し (terminate)、
49 .I "コアダンプファイル (core dump file)"
50 を生成することである。コアダンプファイルは、ディスク上に生成される
51 終了時のプロセスのメモリイメージを内容とするファイルである。
52 このイメージをデバッガ (例えば
53 .BR gdb (1))
54 に読み込んで、
55 プログラムが終了した時点のプログラムの状態を検査することができる。
56 どのシグナルを受けたときにプロセスがコアダンプを生成するかのリストは
57 .BR signal (7)
58 に書かれている。
59
60 .\"O A process can set its soft
61 .\"O .B RLIMIT_CORE
62 .\"O resource limit to place an upper limit on the size of the core dump file 
63 .\"O that will be produced if it receives a "core dump" signal; see
64 .\"O .BR getrlimit (2)
65 .\"O for details.
66 プロセスはソフト・リソース制限
67 .B RLIMIT_CORE
68 を設定することで、「コアダンプ」シグナルを受信した際に生成される
69 コアダンプファイルのサイズに上限を課すことができる。詳細は
70 .BR getrlimit (2)
71 を参照。
72
73 .\"O There are various circumstances in which a core dump file is 
74 .\"O not produced:
75 コアダンプファイルが生成されない状況がいくつかある:
76 .IP * 3
77 .\"O The process does not have permission to write the core file.
78 .\"O (By default the core file is called 
79 .\"O .IR core ,
80 .\"O and is created in the current working directory. 
81 .\"O See below for details on naming.)
82 .\"O Writing the core file will fail if the directory in which 
83 .\"O it is to be created is nonwritable, 
84 .\"O or if a file with the same name exists and 
85 .\"O is not writable
86 .\"O or is not a regular file 
87 .\"O (e.g., it is a directory or a symbolic link).
88 プロセスがコアファイルを書き込む許可を持たない場合
89 (デフォルトでは、コアファイルは
90 .I core
91 という名前で、カレント・ワーキング・ディレクトリに生成される。
92 命名規則の詳細は下記を参照)。
93 コアファイルを生成しようとしたディレクトリが書き込み可能でない場合、
94 もしくは同じ名前のファイルが存在し、そのファイルが書き込み可能でも
95 通常のファイルでもない場合 (例えば、ディレクトリやシンボリックリンク)、
96 コアファイルの生成は失敗する。
97 .IP *
98 .\"O A (writable, regular) file with the same name as would be used for the 
99 .\"O core dump already exists, but there is more than one hard link to that 
100 .\"O file.
101 コアダンプに使おうとしたのと同じ名前の (書き込み可能な、通常の) ファイルが
102 すでに存在し、そのファイルに対するハードリンクが 2個以上ある場合。
103 .IP *
104 .\"O The file system where the core dump file would be created is full; 
105 .\"O or has run out of inodes; or is mounted read-only; 
106 .\"O or the user has reached their quota for the file system.
107 コアダンプファイルを生成しようとしたファイルシステムがフルであるか、
108 inode が全て使用されているか、読み込み専用でマウントされている場合。
109 または、そのユーザのディスク使用量がそのファイルシステムの
110 クオータ (quota) に達している。
111 .IP *
112 .\"O The directory in which the core dump file is to be created does 
113 .\"O not exist.
114 コアダンプファイルを生成しようとしたディレクトリが存在しない場合。
115 .IP *
116 .\"O The
117 .\"O .B RLIMIT_CORE
118 .\"O (core file size) or
119 .\"O .B RLIMIT_FSIZE
120 .\"O (file size) resource limits for the process are set to zero; see
121 .\"O .BR getrlimit (2)
122 .\"O and the documentation of the shell's
123 .\"O .I ulimit
124 .\"O command
125 .\"O .RI ( limit
126 .\"O in
127 .\"O .BR csh (1)).
128 プロセス毎のリソース制限
129 .B RLIMIT_CORE
130 (コアファイルのサイズ) か
131 .B RLIMIT_FSIZE
132 (ファイルサイズ) が 0 に設定されている場合。
133 .BR getrlimit (2)
134 やシェルの
135 .I ulimit
136 コマンドのドキュメント
137 .RB ( csh (1)
138
139 .IR limit )
140 を参照。
141 .IP *
142 .\"O The binary being executed by the process does not have read 
143 .\"O permission enabled.
144 プロセスが実行したバイナリファイルの読み出し許可が有効になっていない場合。
145 .IP *
146 .\"O The process is executing a set-user-ID (set-group-ID) program
147 .\"O that is owned by a user (group) other than the real user (group) 
148 .\"O ID of the process.
149 .\"O (However, see the description of the
150 .\"O .BR prctl (2)
151 .\"O .B PR_SET_DUMPABLE
152 .\"O operation, and the description of the
153 .\"O .I /proc/sys/fs/suid_dumpable
154 .\"O .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
155 .\"O .\" and PR_SET_DUMPABLE to this page?
156 .\"O file in
157 .\"O .BR proc (5).)
158 プロセスが実行している set-user-ID (set-group-ID) プログラムの所有者の
159 ユーザ (グループ) が、プロセスの実 UID (実 GID) と異なる場合
160 (但し、
161 .BR prctl (2)
162 .B PR_SET_DUMPABLE
163 操作の説明と、
164 .BR proc (5)
165
166 .I /proc/sys/fs/suid_dumpable
167 ファイルの説明も参照のこと)。
168 .\" FIXME . Perhaps relocate discussion of /proc/sys/fs/suid_dumpable
169 .\" and PR_SET_DUMPABLE to this page?
170 .\"O .SS Naming of core dump files
171 .SS コアダンプファイルの名前
172 .\"O By default, a core dump file is named 
173 .\"O .IR core ,
174 .\"O but the 
175 .\"O .I /proc/sys/kernel/core_pattern
176 .\"O file (since Linux 2.6 and 2.4.21)
177 .\"O can be set to define a template that is used to name core dump files.
178 .\"O The template can contain % specifiers which are substituted
179 .\"O by the following values when a core file is created:
180 .\" motoki XXX 同じ内容が重複して書かれている。
181 デフォルトでは、コアダンプファイルの名前は
182 .I core
183 となるが、コアダンプファイルの名前を決めるのに使われるテンプレートを
184 .I /proc/sys/kernel/core_pattern
185 ファイルに定義することで、ファイル名を変更することができる
186 .RI ( /proc/sys/kernel/core_pattern
187 は Linux 2.6 および 2.4.21 以降で利用できる)。
188 テンプレートには % 指示子 (specifier) を入れることができる。
189 これはコアファイルが生成される際に、以下の値に置き換えられる。
190 .PP
191 .RS 4
192 .PD 0
193 .TP 4
194 %%
195 .\"O a single % character
196 1 つの % 文字
197 .TP
198 %p
199 .\"O PID of dumped process
200 ダンプされたプロセスのプロセスID (PID)
201 .TP
202 %u
203 .\"O (numeric) real UID of dumped process
204 ダンプされたプロセスの実ユーザ ID (real UID)
205 .TP
206 %g
207 .\"O (numeric) real GID of dumped process
208 ダンプされたプロセスの実グループ ID (real GID)
209 .TP
210 %s
211 .\"O number of signal causing dump
212 ダンプを引き起こしたシグナルの番号
213 .TP
214 %t
215 .\"O time of dump, expressed as seconds since the
216 .\"O Epoch, 1970-01-01 00:00:00 +0000 (UTC)
217 ダンプ時刻、紀元 (Epoch; 1970-01-01 00:00:00 +0000 (UTC))
218 からの秒数。
219 .TP
220 %h
221 .\"O hostname (same as \fInodename\fP returned by \fBuname\fP(2))
222 ホスト名 (\fBuname\fP(2) で返される \fInodename\fP と同じ)
223 .TP
224 %e
225 .\"O executable filename (without path prefix)
226 実行ファイル名 (パス名のプレフィックスは含まれない)
227 .TP
228 %c
229 .\"O core file size soft resource limit of crashing process (since Linux 2.6.24)
230 クラッシュしたプロセスのコアファイルのサイズに関するソフトリソース上限
231 (Linux 2.6.24 以降)
232 .PD
233 .RE
234 .PP
235 .\"O A single % at the end of the template is dropped from the 
236 .\"O core filename, as is the combination of a % followed by any 
237 .\"O character other than those listed above.
238 テンプレートの末尾に 1 個だけ % がある場合、
239 その % はコアファイル名には含められない。また、上で列挙されて
240 いない % と文字の組み合わせがあった場合も同様である。
241 .\"O All other characters in the template become a literal
242 .\"O part of the core filename.
243 テンプレートにおける他の文字は、
244 コアファイル名としてそのまま使われる。
245 .\"O The template may include \(aq/\(aq characters, which are interpreted
246 .\"O as delimiters for directory names.
247 テンプレートには \(aq/\(aq 文字を入れることができ、
248 ディレクトリ名の区切り文字と解釈される。
249 .\"O The maximum size of the resulting core filename is 128 bytes (64 bytes
250 .\"O in kernels before 2.6.19).
251 結果として生成されるコアファイル名の最大サイズは 128 バイトである
252 (2.6.19 より前のカーネルでは 64 バイト)。
253 .\"O The default value in this file is "core".
254 このファイルのデフォルト値は "core" である。
255 .\"O For backward compatibility, if
256 .\"O .I /proc/sys/kernel/core_pattern
257 .\"O does not include "%p" and
258 .\"O .I /proc/sys/kernel/core_uses_pid
259 .\"O (see below)
260 .\"O is nonzero, then .PID will be appended to the core filename.
261 以前のものとの互換性のため、
262 .I /proc/sys/kernel/core_pattern
263 に "%p" が含まれず、
264 かつ
265 .I /proc/sys/kernel/core_uses_pid
266 (下記参照) が 0 でない場合は、.PID がコアファイル名に追加される。
267
268 .\"O Since version 2.4, Linux has also provided
269 .\"O a more primitive method of controlling
270 .\"O the name of the core dump file.
271 .\"O If the
272 .\"O .I /proc/sys/kernel/core_uses_pid
273 .\"O file contains the value 0, then a core dump file is simply named
274 .\"O .IR core .
275 .\"O If this file contains a nonzero value, then the core dump file includes
276 .\"O the process ID in a name of the form
277 .\"O .IR core.PID .
278 バージョン 2.4 以降の Linux では
279 コアダンプファイルの名前を制御する原始的な方法も提供されている。
280 .I /proc/sys/kernel/core_uses_pid
281 ファイルに値 0 が書かれている場合、コアダンプファイルは単純に
282 .I core
283 という名前になる。このファイルに 0 以外の値が書かれている場合、
284 コアダンプファイルは
285 .I core.PID
286 という形式の名前になり、ファイル名にプロセス ID が含まれる。
287 .\"O .SS Piping core dumps to a program
288 .SS コアダンプのプログラムへのパイプ
289 .\"O Since kernel 2.6.19, Linux supports an alternate syntax for the
290 .\"O .I /proc/sys/kernel/core_pattern
291 .\"O file.
292 .\"O If the first character of this file is a pipe symbol (\fB|\fP),
293 .\"O then the remainder of the line is interpreted as a program to be
294 .\"O executed.
295 .\"O Instead of being written to a disk file, the core dump is given as
296 .\"O standard input to the program.
297 .\"O Note the following points:
298 カーネル 2.6.19 以降では、Linux は
299 .I /proc/sys/kernel/core_pattern
300 ファイルの別の構文をサポートしている。
301 このファイルの最初の文字がパイプ記号 (\fB|\fP) であれば、
302 その行の残りの部分は実行するプログラムとして解釈される。
303 コアダンプは、ディスク上のファイルに書き込まれるのではなく、
304 プログラムの標準入力として渡される。
305 以下の点に注意すること。
306 .IP * 3
307 .\"O The program must be specified using an absolute pathname (or a
308 .\"O pathname relative to the root directory, \fI/\fP),
309 .\"O and must immediately follow the '|' character.
310 プログラムは絶対パス名 (もしくはルートディレクトリ \fI/\fP からの
311 相対パス名) で指定されなければならない。
312 また、'|' 文字の直後から始めなければならない。
313 .IP *
314 .\"O The process created to run the program runs as user and group
315 .\"O .IR root .
316 プログラムを実行するために生成されるプロセスは、
317 ユーザ、グループとも
318 .I root 
319 として実行される。
320 .IP *
321 .\"O Command-line arguments can be supplied to the
322 .\"O program (since kernel 2.6.24),
323 .\"O delimited by white space (up to a total line length of 128 bytes).
324 コマンドライン引き数をプログラムに与えることができ (カーネル 2.6.24 以降)、
325 引き数はホワイトスペースで区切る
326 (1行の最大長は 128 バイトが上限である)。
327 .IP *
328 .\"O The command-line arguments can include any of
329 .\"O the % specifiers listed above.
330 .\"O For example, to pass the PID of the process that is being dumped, specify
331 .\"O .I %p
332 .\"O in an argument.
333 コマンドライン引き数には、上記のリストにある % 指示子を含めることができる。
334 例えば、ダンプされるプロセスの PID を渡すには、
335 引き数に
336 .I %p
337 を指定する。
338 .\"O .SS Controlling which mappings are written to the core dump
339 .SS どのマッピングをコアダンプに書き込むかを制御する
340 .\"O Since kernel 2.6.23, the Linux-specific
341 .\"O .IR /proc/PID/coredump_filter
342 .\"O file can be used to control which memory segments are written to the
343 .\"O core dump file in the event that a core dump is performed for the
344 .\"O process with the corresponding process ID.
345 カーネル 2.6.23 以降では、Linux 固有のファイル
346 .I /proc/PID/coredump_filter
347 を使って、対応するプロセス ID を持つプロセスに対してコアダンプが行われる
348 際に、どのメモリセグメントをコアダンプファイルに書き込むかを制御できる。
349
350 .\"O The value in the file is a bit mask of memory mapping types (see
351 .\"O .BR mmap (2)).
352 .\"O If a bit is set in the mask, then memory mappings of the
353 .\"O corresponding type are dumped; otherwise they are not dumped.
354 .\"O The bits in this file have the following meanings:
355 このファイルの値はメモリマッピング種別
356 .RB ( mmap (2)
357 参照) のビットマスクである。
358 マスク内のあるビットがセットされると、そのビットに対応する種別の
359 メモリマッピングがダンプされる。セットされていないものはダンプされない。
360 このファイルの各ビットは以下の意味を持つ。
361 .PP
362 .PD 0
363 .RS 4
364 .TP
365 bit 0
366 .\"O Dump anonymous private mappings.
367 無名のプライベートマッピング (anonymous private mappings) をダンプする。
368 .TP
369 bit 1
370 .\"O Dump anonymous shared mappings.
371 無名の共有マッピング (anonymous shared mappings) をダンプする。
372 .TP
373 bit 2
374 .\"O Dump file-backed private mappings.
375 ファイルと関連付けられたプライベートマッピング
376 (file-backed private mappings) をダンプする。
377 .TP
378 bit 3
379 .\"O Dump file-backed shared mappings.
380 ファイルと関連付けられた共有マッピング
381 (file-backed shared mappings) をダンプする。
382 .\" file-backed shared mappings of course also update the underlying
383 .\" mapped file.
384 .TP
385 .\"O bit 4 (since Linux 2.6.24)
386 .\"O Dump ELF headers.
387 bit 4 (Linux 2.6.24 以降)
388 ELF ヘッダをダンプする。
389 .TP
390 .\"O bit 5 (since Linux 2.6.28)
391 .\"O Dump private huge pages.
392 bit 5 (Linux 2.6.28 以降)
393 プライベートなヒュージページ (private huge page) をダンプする。
394 .TP
395 .\"O bit 6 (since Linux 2.6.28)
396 .\"O Dump shared huge pages.
397 bit 6 (Linux 2.6.28 以降)
398 共有されたヒュージページ (shared huge page) をダンプする。
399 .RE
400 .PD
401 .PP
402 .\"O By default, the following bits are set: 0, 1, 4 (if the
403 .\"O .B CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
404 .\"O kernel configuration option is enabled), and 5.
405 .\"O The value of this file is displayed in hexadecimal.
406 .\"O (The default value is thus displayed as 33.)
407 デフォルトでは、ビット 0, 1, 4, 5 がセットされる。
408 (ビット 4 がセットされるのは、カーネルが設定オプション
409 .B CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS
410 を有効にして作成された場合である)。
411 このファイルの値は 16 進形式で表示される
412 (したがって、デフォルト値は 33 と表示される)。
413
414 .\"O Memory-mapped I/O pages such as frame buffer are never dumped, and
415 .\"O virtual DSO pages are always dumped, regardless of the
416 .\"O .I coredump_filter
417 .\"O value.
418 .I coredump_filter
419 の値に関わらず、フレームバッファなどの memory-mapped I/O に関する
420 ページは決してダンプされず、仮想 DSO ページは常にダンプされる。
421
422 .\"O A child process created via
423 .\"O .BR fork (2)
424 .\"O inherits its parent's
425 .\"O .I coredump_filter
426 .\"O value;
427 .\"O the
428 .\"O .I coredump_filter
429 .\"O value is preserved across an
430 .\"O .BR execve (2).
431 .BR fork (2)
432 で作成される子プロセスは親プロセスの
433 .I coredump_filter
434 の値を継承する。
435 .BR execve (2)
436 の前後で
437 .I coredump_filter
438 の値は保持される。
439
440 .\"O It can be useful to set
441 .\"O .I coredump_filter
442 .\"O in the parent shell before running a program, for example:
443 例のように、プログラムを実行する前に親シェルの
444 .I coredump_filter
445 を設定しておくと役立つことがある。
446
447 .in +4n
448 .nf
449 .RB "$" " echo 0x7 > /proc/self/coredump_filter"
450 .RB "$" " ./some_program"
451 .fi
452 .in
453 .PP
454 .\"O This file is only provided if the kernel was built with the
455 .\"O .B CONFIG_ELF_CORE
456 .\"O configuration option.
457 このファイルが提供されるのは、カーネルが設定オプション
458 .B CONFIG_ELF_CORE
459 を有効にして作成された場合だけである。
460 .\"O .SH NOTES
461 .SH 備考
462 .\"O The 
463 .\"O .BR gdb (1)
464 .\"O .I gcore
465 .\"O command can be used to obtain a core dump of a running process.
466 .BR gdb (1)
467
468 .I gcore
469 コマンドを使用すると、実行中のプロセスのコアダンプを取得できる。
470
471 .\"O If a multithreaded process (or, more precisely, a process that
472 .\"O shares its memory with another process by being created with the
473 .\"O .B CLONE_VM
474 .\"O flag of
475 .\"O .BR clone (2))
476 .\"O dumps core, then the process ID is always appended to the core filename, 
477 .\"O unless the process ID was already included elsewhere in the
478 .\"O filename via a %p specification in
479 .\"O .IR /proc/sys/kernel/core_pattern .
480 マルチスレッドプロセス
481 (より正確には、
482 .BR clone (2)
483
484 .B CLONE_VM
485 で生成された別プロセスとメモリを共有しているプロセス)
486 がコアダンプを生成する場合、
487 コアファイル名にプロセス ID が必ず付加される。
488 ただし、
489 .I /proc/sys/kernel/core_pattern
490 の %p 指定によりコアファイル名のどこか他の場所にプロセス ID が
491 すでに含まれている場合は、プロセス ID が末尾に付加されない。
492 .\"O (This is primarily useful when employing the LinuxThreads implementation,
493 .\"O where each thread of a process has a different PID.)
494 (この機能がまず役に立つのは LinuxThreads 実装を利用している場合である。
495 LinuxThreads 実装では、プロセス内の個々のスレッドは異なるプロセス ID
496 を持つ。)
497 .\" Always including the PID in the name of the core file made
498 .\" sense for LinuxThreads, where each thread had a unique PID,
499 .\" but doesn't seem to serve any purpose with NPTL, where all the 
500 .\" threads in a process share the same PID (as POSIX.1 requires).  
501 .\" Probably the behavior is maintained so that applications using 
502 .\" LinuxThreads continue appending the PID (the kernel has no easy 
503 .\" way of telling which threading implementation the userspace 
504 .\" application is using). -- mtk, April 2006
505 .\"O .SH EXAMPLE
506 .SH 例
507 .\"O The program below can be used to demonstrate the use of the
508 .\"O pipe syntax in the
509 .\"O .I /proc/sys/kernel/core_pattern
510 .\"O file.
511 .\"O The following shell session demonstrates the use of this program
512 .\"O (compiled to create an executable named
513 .\"O .IR core_pattern_pipe_test ):
514 以下のプログラムは
515 .I /proc/sys/kernel/core_pattern
516 ファイルのパイプ構文の使用例を示している。
517 以下のシェルのセッションはこのプログラムの使用例を示すものである
518 (コンパイルして
519 .I core_pattern_pipe_test
520 という名前の実行ファイルを作成している)。
521 .PP
522 .in +4n
523 .nf
524 .RB "$" " cc \-o core_pattern_pipe_test core_pattern_pipe_test.c"
525 .RB "$" " su"
526 Password:
527 .RB "#" " echo \(dq|$PWD/core_pattern_pipe_test %p \
528 UID=%u GID=%g sig=%s\(dq > \e"
529 .B "    /proc/sys/kernel/core_pattern"
530 .RB "#" " exit"
531 .RB "$" " sleep 100"
532 .BR "^\e" "                     # type control-backslash"
533 Quit (core dumped)
534 .RB "$" " cat core.info"
535 argc=5
536 argc[0]=</home/mtk/core_pattern_pipe_test>
537 argc[1]=<20575>
538 argc[2]=<UID=1000>
539 argc[3]=<GID=100>
540 argc[4]=<sig=3>
541 Total bytes in core dump: 282624
542 .fi
543 .in
544 .\"O .SS Program source
545 .SS プログラムのソース
546 \&
547 .nf
548 /* core_pattern_pipe_test.c */
549
550 #define _GNU_SOURCE
551 #include <sys/stat.h>
552 #include <fcntl.h>
553 #include <limits.h>
554 #include <stdio.h>
555 #include <stdlib.h>
556 #include <unistd.h>
557
558 #define BUF_SIZE 1024
559
560 int
561 main(int argc, char *argv[])
562 {
563     int tot, j;
564     ssize_t nread;
565     char buf[BUF_SIZE];
566     FILE *fp;
567     char cwd[PATH_MAX];
568
569     /* Change our current working directory to that of the
570        crashing process */
571
572     snprintf(cwd, PATH_MAX, "/proc/%s/cwd", argv[1]);
573     chdir(cwd);
574
575     /* Write output to file "core.info" in that directory */
576
577     fp = fopen("core.info", "w+");
578     if (fp == NULL)
579         exit(EXIT_FAILURE);
580
581     /* Display command\-line arguments given to core_pattern
582        pipe program */
583
584     fprintf(fp, "argc=%d\\n", argc);
585     for (j = 0; j < argc; j++)
586         fprintf(fp, "argc[%d]=<%s>\\n", j, argv[j]);
587
588     /* Count bytes in standard input (the core dump) */
589
590     tot = 0;
591     while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
592         tot += nread;
593     fprintf(fp, "Total bytes in core dump: %d\\n", tot);
594
595     exit(EXIT_SUCCESS);
596 }
597 .fi
598 .\"O .SH SEE ALSO
599 .SH 関連項目
600 .BR bash (1),
601 .BR gdb (1),
602 .BR getrlimit (2),
603 .BR mmap (2),
604 .BR prctl (2),
605 .BR sigaction (2),
606 .BR elf (5),
607 .BR proc (5),
608 .BR pthreads (7),
609 .BR signal (7)