最近、Linuxを使うことは減ってきたのですが、
- どんどん新しい技術が生まれるこの世界で10年効く技術とは何だろうと思ったこと、
- そしてそれを身に付けてみたいと思い
読んでみました。
読みながら試してみたことを以下にまとめておきます。
bigram.plをRubyで書き換えてみる
第3章では、シェルスクリプトやPerlスクリプトの紹介がありますが、p186のbigramによる自動執筆スクリプトをRubyで書き換えてみました。
bigram.rb
#!/usr/bin/env ruby def build_bigram bigram = Hash.new{|h, k| h[k] = []} pre = '' while line = gets line.chomp! words = line.split(/\s+/) words.each {|word| bigram[pre] << word pre = word } end bigram end if __FILE__ == $0 bigram = build_bigram pre = 'I'; print "I " 100.times { candidates = bigram[pre] choice = candidates.sample print choice + " " pre = choice } end
実行結果
$ ./bigram.rb < 28054.txt
I find the fit for the left the bride or to it. And he wanted to the object of that, too, was still fly with the kneeling and sympathetic and that are the trial," he turned out of the mushrooms or any effort to open the mother, and the dawning woman I left his hands. Too, too unhappy son," Ippolit Kirillovitch's, but simply for my dear friend' of something for one in my betrothed. And they had till that the villages and honored guest!" and don't you won't come back, motionless, on the soul quivering with Katerina Ivanovna, with me, because
カーネルソースを読む準備
第4章は、「最後の砦! カーネルソースを読む」で、とても興味深い内容でした。自分の環境(Mac)でも読めるように準備をしました。
- Vagrantのインストール
http://www.vagrantup.com/downloads.html
- VirtulBoxのインストール
https://www.virtualbox.org/wiki/Downloads
Macbook-Pro:~ $ vagrant init hashicorp/precise64 Macbook-Pro:~ $ vagrant up Macbook-Pro:~ $ vagrant ssh vagrant@precise64:/$ sudo apt-get update vagrant@precise64:/$ sudo apt-get install linux-source vagrant@precise64:/$ cd /usr/src vagrant@precise64:/usr/src$ sudo tar jxvf linux-source-3.2.0.tar.bz2
- p212を試してみる
vagrant@precise64:/usr/src/linux-source-3.2.0$ grep -Hr --binary-files=without-match "linux_banner" ./init/ ./init/main.c: printk(KERN_NOTICE "%s", linux_banner); ./init/version.c:const char linux_banner[] =
感想
大学時代に初めてLinuxに触れてから今まで、カーネルソースを読んでみようと思ったことはなかった*1ので、第4章の「最後の砦! カーネルソースを読む」はとても参考になりました。特に、大学時代に習った連結リストをgrepで探しあてたときには、習ったことが実際に役立っていることにとても感動しました。
vagrant@precise64:/usr/src/linux-source-3.2.0$ grep -Hr --binary-files=without-match "struct list_head {" ./include ./include/linux/types.h:struct list_head {
プロのための Linuxシステム・10年効く技術 (Software Design plus)
- 作者: 中井悦司
- 出版社/メーカー: 技術評論社
- 発売日: 2012/06/15
- メディア: 大型本
- 購入: 6人 クリック: 88回
- この商品を含むブログ (18件) を見る
*1:実際にはあったのですが初期の早い段階で挫折してしまいました…。