驚動大神的JavaScript:在Web上運(yùn)行Linux
一個(gè)叫Fabrice Bellard的程序員寫了一段Javascript在Web瀏覽器中啟動Linux(原網(wǎng)頁,我把這個(gè)網(wǎng)頁iframe在了下面),目前,你只能使用Firefox 4和Chrome 11運(yùn)行這個(gè)Linux。這不是什么假的模仿Linux的東西,這是實(shí)實(shí)在在的運(yùn)行一個(gè)Linux。這一舉動還引起了很多很牛人的關(guān)注,包括Javascript的創(chuàng)建者Brendan Eich。
- IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
- TCP established hash table entries: 1024 (order: 0, 4096 bytes)
- TCP bind hash table entries: 512 (order: -1, 2048 bytes)
- TCP: Hash tables configured (established 1024 bind 512)
- TCP reno registered
- checking if image is initramfs...it isn't (bad gzip magic numbers); looks like a
- n initrd
- Freeing initrd memory: 2048k freed
- Total HugeTLB memory allocated, 0
- io scheduler noop registered
- io scheduler anticipatory registered
- io scheduler deadline registered
- io scheduler cfq registered (default)
- Real Time Clock Driver v1.12ac
- JS clipboard: I/O at 0x03c0
- Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing disabled
- serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16450
- RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
- loop: loaded (max 8 devices)
- TCP cubic registered
- NET: Registered protocol family 1
- NET: Registered protocol family 17
- Using IPI Shortcut mode
- Time: pit clocksource has been installed.
- RAMDISK: ext2 filesystem found at block 0
- RAMDISK: Loading 2048KiB [1 disk] into ram disk... done.
- VFS: Mounted root (ext2 filesystem).
- Freeing unused kernel memory: 124k freed
- W
- IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
- TCP established hash table entries: 1024 (order: 0, 4096 bytes)
- TCP bind hash table entries: 512 (order: -1, 2048 bytes)
- TCP: Hash tables configured (established 1024 bind 512)
- TCP reno registered
- checking if image is initramfs...it isn't (bad gzip magic numbers); looks like a
- n initrd
- Freeing initrd memory: 2048k freed
- Total HugeTLB memory allocated, 0
- io scheduler noop registered
- io scheduler anticipatory registered
- io scheduler deadline registered
- io scheduler cfq registered (default)
- Real Time Clock Driver v1.12ac
- JS clipboard: I/O at 0x03c0
- Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing disabled
- serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16450
- RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
- loop: loaded (max 8 devices)
- TCP cubic registered
- NET: Registered protocol family 1
- NET: Registered protocol family 17
- Using IPI Shortcut mode
- Time: pit clocksource has been installed.
- RAMDISK: ext2 filesystem found at block 0
- RAMDISK: Loading 2048KiB [1 disk] into ram disk... done.
- VFS: Mounted root (ext2 filesystem).
- Freeing unused kernel memory: 124k freed
- Welcome to JS/Linux
隨后,F(xiàn)abrice Bellard發(fā)布了相關(guān)的技術(shù)說明:http://bellard.org/jslinux/tech.html,從這份文檔中我們可以看到:
這個(gè)模似器完全由Javascript寫成
CPU仿真器使用的是QEMU(接近于原古的486),為了裝上Linux,其做了一些改動。
Javascript的終端本來可以使用termlib,但他還是自己寫了一個(gè),因?yàn)镺S的按鍵和Web瀏覽器不一樣(here)
Linux 使用了2.6.20內(nèi)核,編譯配置在這里,并做了一些小改動。
磁盤用的是Ram Disk,在啟動的時(shí)候裝載。其文件系統(tǒng)由Buildroot 和BusyBox產(chǎn)生。
在Home目錄下有一個(gè)hello.c的程序,你可以使用TinyCC編譯(tcc,參看酷殼的這篇文章)
從這個(gè)事我有這些感觸,
在Web上運(yùn)行一個(gè)Linux的操作系統(tǒng)不是問題。那么在Web上還有什么不能做的嗎?
Linux真是性能很高,在Javascript下運(yùn)行感覺也不慢啊。
真是Techno-Geek。
原文鏈接:http://coolshell.cn/articles/4722.html#more-4722
【編輯推薦】