トップ «前の日記(2007-04-09) 最新 次の日記(2007-04-11)» 編集

日々の破片

著作一覧

2007-04-10

_ fork&exec

というか、sodaさんが既にポイントしてくださったEarly Unix history and evolution(PDF)に出ているように思うように思うような(ちょっと、僕にはこの英文は厳しい。なんでだろう?)。

厳しいので拾い読み。誤訳の指摘、歓迎です。

By `process control,' I mean the mechanisms by which processes are created and used; today the system calls fork, exec, wait, and exit implement these mechanisms. Unlike the file system, which existed in nearly its present form from the earliest days, the process control scheme underwent considerable mutation after PDP-7 Unix was already in use.

プロセスコントロールという言葉は、プロセスを生成して呼び出すメカニズムを意味する。今日のシステムコールつまり、fork、exec、wait、exitはこのメカニズムの実装である。ファイルシステムと異なり、初期のUnix実装のころからこのようなプロセス制御の仕組みは存在していた。これはPDP-7 Unixで既に利用されていたプロセス制御スキーマを変形させたものである。

(今日の、fork-exec-wait-exitのプロトコル説明は省略)

Processes (independently executing entities) existed very early in PDP-7 Unix. There were in fact precisely two of them, one for each of the two terminals attached to the machine. There was no fork, wait, or exec. There was an exit, but its meaning was rather different, as will be seen. The main loop of the shell went as follows.

プロセス(独立した実行単位)はPDP-7 Unixの初期から存在する。これらは実際には、正確に2つのプロセスしか存在しない。1つのマシンに接続した2つのターミナルということである。forkは無かった。wait、execもだ。exitがあるだけだ。しかし、その意味は、これから説明するように多少異なる。シェルのメインループは以下のようになる。

1)

The shell closed all its open files, then opened the terminal special file for standard input and output (file descriptors 0 and 1).

シェルはすべてのオープンしたファイルをクローズして、次にターミナルのスペシャルファイル(標準入力と標準出力――FDは0と1)を開く

2)

It read a command line from the terminal.

シェルはターミナルからコマンドラインを読み取る

3)

It linked to the file specifying the command, opened the file, and removed the link. Then it copied a small bootstrap program to the top of memory and jumped to it; this bootstrap program read in the file over the shell code, then jumped to the first location of the command (in effect an exec).

コマンドで指定されたファイルをリンクし、オープンし、次にリンクを削除する。そして小さなブートストラッププログラムをメモリーの先頭にコピーして次にそこへ制御を移す。このブートストラッププログラムはシェルプログラムを上書きするかたちでコマンドファイルを読み込み、次にコマンドの先頭に制御を移す(つまりexecである)

4)

The command did its work, then terminated by calling exit. The exit call caused the system to read in a fresh copy of the shell over the terminated command, then to jump to its start (and thus in effect to go to step 1).

コマンドは自分の仕事を実行する。次に、exitを呼び出し終結する。exitコールはシステムにシェルの新しいコピーを終結したプログラムを上書きする形で読み込むことを要求する。そしてその先頭に制御を移す(そしてステップ1へ戻る)

面倒なので、ここまで。

ここからわかることは、Unixがまだfork/exec/wait/exitを持たないうちから、標準入出力の用意(パイプがあろうがなかろうが、ターミナルに対して必要)、プログラム自身への次に実行するプログラムの上書き、といった操作を行っているということだ。

で、sodaさんが特定している個所が来る。

Process control in its modern form was designed and implemented within a couple of days. It is astonishing how easily it fitted into the existing system; at the same time it is easy to see how some of the slightly unusual features of the design are present precisely because they represented small, ……(引用するより、リンク先を参照するほうが早いと思うので、ここまで。この節が結論となっています)

本日のツッコミ(全3件) [ツッコミを入れる]
_ soda (2007-04-11 12:23)

あとは Berkeley time-sharing system の方の著者にも注目です。<br>Peter Deutch と Butler Lampson ですからねえ。

_ arton (2007-04-11 23:45)

まったく知りませんでした。<br>http://ja.wikipedia.org/wiki/%E3%83%90%E3%83%88%E3%83%A9%E3%83%BC%E3%83%BB%E3%83%A9%E3%83%B3%E3%83%97%E3%82%BD%E3%83%B3<br>すごい人(たち)なんですね。<br>http://research.microsoft.com/Lampson/04-OnlineEditor/04-OnlineEditor.htm<br>ランプソンって今はMSRの人なのかな?

_ soda (2007-04-12 12:23)

Butler Lampson は今は MSR ですね。<br>私は「実録天才プログラマー」という(タイトルが恥ずかしいけど中身は素晴らしい)本で最初に知りました。<br>二人は Xerox PARC の主要メンバーでもあったので、「未来をつくった人々―ゼロックス・パロアルト研究所とコンピュータエイジの黎明」にも載ってたと思います。<br>Peter Deutch は Ghostscript の作者でもあったりするので、日頃から間接的にお世話になりまくりの偉い人なんですが、Butler Lampson はさらに輪をかけて、極めて賢い人らしいです。


2003|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

ジェズイットを見習え