プロセス識別子
[Wikipedia|▼Menu]

プロセス識別子(プロセスしきべつし、プロセスID、PIDと略記)は、いくつかのオペレーティングシステムカーネルUnix系Windows)で使われている番号で、ある時点で存在するプロセスを一意に識別するために用いられる。優先順位を調整したり、終了させたり等、プロセス(群)を操作する様々な関数の引数として使う。
概要

Unix系OSでは、新たなプロセスは fork() システムコールで生成される。そのときに生成された子プロセスのPIDがシステムコールを行った親プロセスに戻り値として返される。すると親プロセスは例えば、子プロセスの終了を waitpid()(英語版) 関数で待ち合わせたり、kill() でプロセスを終了させたりする。

Unix系OSでは、プロセス識別子 0 と 1 は特別なタスクを指している。プロセス識別子 0 は swapper または sched と呼ばれ、ページングを担当している。これは実はカーネルの一部であり、ユーザーモードのプロセスではない。プロセス識別子 1 は init プロセスで、主にシステムの立ち上げとシャットダウンを担当している。本来、プロセス識別子 1 は init のために予約されていたわけではなく、単にカーネルが最初に起動するプロセスだったためにこのPIDが init に付与されただけだった。最近のUnix系OSはカーネルの複数のコンポーネントをプロセスとして見せていることがある。その場合、PID 1 は init プロセス用に積極的に予約されていて、古いシステムとの互換性を保っている。カーネルスレッドをサポートするシステムでは、カーネルの複数のプロセスはスレッドとして識別され、プロセス識別子は0しか使用しないこともある。

Unix系OSでは、プロセス識別子はプロセスが生成される順に0から始めて値の小さいほうから付けていく。PIDの最大値はシステムによって異なる。最大値まで使ったとき、PID割り当ては例えば300に戻されて、再び増加していく。macOSHP-UX では巻き戻し時の開始番号は100となっている。そのとき、現存しているプロセスが使用中のPIDはスキップして二重に割り当てないようにする。この性質を利用してシステムに関する情報を抽出可能であり、このことが潜在的なセキュリティ上の脆弱性だと考える者もいる。そのため、セキュリティ強化を心がけた実装をする場合、PID割り当て方針を通常とは異なるものにすることもある[1]MPE/iX などのシステムでは、利用可能な最小のPIDを使用し(つまり、終了したプロセスのPIDを即座に再利用することがある)、メモリ上のプロセス情報のカーネルページ数を最小化する。

Microsoft Windows では、自身のプロセス識別子は GetCurrentProcessId() というAPIで取得し[2]、他のプロセスのプロセス識別子は GetProcessId() というAPIで取得する[3]。内部的にはプロセス識別子を client ID と呼び、thread ID と同じ名前空間から割り当てられるので、両者は決してオーバーラップしない。いわゆるシステムアイドルプロセス(英語版)のプロセス識別子は0で、システムプロセスのプロセス識別子は4が割り当てられる。

Unix系OSでは、自身のプロセス識別子は getpid() システムコールで得られ、シェルでは $$ という変数で得られる。親プロセスのプロセス識別子は getppid() システムコールで得られる。

Linuxでは、プロセス識別子の最大値は擬似ファイル .mw-parser-output .monospaced{font-family:monospace,monospace}/proc/sys/kernel/pid_max にある[4]
pidファイル

長時間動作し続けるプロセス(例えば MySQL デーモンなど)は、自身のPIDをファイルに書いておき、他のプロセスが参照できるようにしていることがある。
脚注^ “ ⇒comp.unix.aix Frequently Asked Questions”. 2008年7月21日閲覧。
^ “ ⇒GetCurrentProcessId Function”. Windows Developer Center. 2009年5月20日閲覧。
^ “ ⇒ProcessId Function”. Windows Developer Center. 2011年3月5日閲覧。
^ “ ⇒proc - process information pseudo-filesystem”. Linux Programmer's Manual. 2009年12月28日閲覧。

参考文献

.mw-parser-output .citation{word-wrap:break-word}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}この記事は2008年11月1日以前にFree On-line Dictionary of Computingから取得した項目の資料を元に、GFDL バージョン1.3以降の「RELICENSING」(再ライセンス) 条件に基づいて組み込まれている。
関連項目

pidof

ユーザー識別子 (UID)

グループ識別子 (GID)
.mw-parser-output .asbox{position:relative;overflow:hidden}.mw-parser-output .asbox table{background:transparent}.mw-parser-output .asbox p{margin:0}.mw-parser-output .asbox p+p{margin-top:0.25em}.mw-parser-output .asbox{font-size:90%}.mw-parser-output .asbox-note{font-size:90%}.mw-parser-output .asbox .navbar{position:absolute;top:-0.90em;right:1em;display:none}

この項目は、コンピュータに関連した書きかけの項目です。この項目を加筆・訂正などしてくださる協力者を求めていますPJ:コンピュータ/P:コンピュータ)。
.mw-parser-output .hlist ul,.mw-parser-output .hlist ol{padding-left:0}.mw-parser-output .hlist li,.mw-parser-output .hlist dd,.mw-parser-output .hlist dt{margin-right:0;display:inline-block;white-space:nowrap}.mw-parser-output .hlist dt:after,.mw-parser-output .hlist dd:after,.mw-parser-output .hlist li:after{white-space:normal}.mw-parser-output .hlist li:after,.mw-parser-output .hlist dd:after{content:" ・\a0 ";font-weight:bold}.mw-parser-output .hlist dt:after{content:": "}.mw-parser-output .hlist-pipe dd:after,.mw-parser-output .hlist-pipe li:after{content:" |\a0 ";font-weight:normal}.mw-parser-output .hlist-hyphen dd:after,.mw-parser-output .hlist-hyphen li:after{content:" -\a0 ";font-weight:normal}.mw-parser-output .hlist-comma dd:after,.mw-parser-output .hlist-comma li:after{content:"、";font-weight:normal}.mw-parser-output .hlist-slash dd:after,.mw-parser-output .hlist-slash li:after{content:" /\a0 ";font-weight:normal}.mw-parser-output .hlist dd:last-child:after,.mw-parser-output .hlist dt:last-child:after,.mw-parser-output .hlist li:last-child:after{content:none}.mw-parser-output .hlist dd dd:first-child:before,.mw-parser-output .hlist dd dt:first-child:before,.mw-parser-output .hlist dd li:first-child:before,.mw-parser-output .hlist dt dd:first-child:before,.mw-parser-output .hlist dt dt:first-child:before,.mw-parser-output .hlist dt li:first-child:before,.mw-parser-output .hlist li dd:first-child:before,.mw-parser-output .hlist li dt:first-child:before,.mw-parser-output .hlist li li:first-child:before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child:after,.mw-parser-output .hlist dd dt:last-child:after,.mw-parser-output .hlist dd li:last-child:after,.mw-parser-output .hlist dt dd:last-child:after,.mw-parser-output .hlist dt dt:last-child:after,.mw-parser-output .hlist dt li:last-child:after,.mw-parser-output .hlist li dd:last-child:after,.mw-parser-output .hlist li dt:last-child:after,.mw-parser-output .hlist li li:last-child:after{content:")\a0 ";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li:before{content:" "counter(listitem)" ";white-space:nowrap}.mw-parser-output .hlist dd ol>li:first-child:before,.mw-parser-output .hlist dt ol>li:first-child:before,.mw-parser-output .hlist li ol>li:first-child:before{content:" ("counter(listitem)" "}.mw-parser-output .navbar{display:inline;font-size:75%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}.mw-parser-output .infobox .navbar{font-size:88%}.mw-parser-output .navbox .navbar{display:block;font-size:88%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}


次ページ
記事の検索
おまかせリスト
▼オプションを表示
ブックマーク登録
mixiチェック!
Twitterに投稿
オプション/リンク一覧
話題のニュース
列車運行情報
暇つぶしWikipedia

Size:11 KB
出典: フリー百科事典『ウィキペディア(Wikipedia)
担当:undef