"Worse is better" -- Unix哲学之一

本段文字介绍了Unix哲学之一:Worse is Better,同时本文还解释了为什么Unix阻塞系统调用可能会返回EINTR错误。

 

Richard P. Gabriel suggests that a key advantage of Unix was that it embodied a design philosophy he termed "Worse is better". In the "Worse is better" design style, simplicity of both the interface and the implementation is more important than any other attribute of the system — including correctness, consistency and completeness. Gabriel argues that this design style has key evolutionary advantages, though he questions the quality of some results.

 

For example, in the early days UNIX was a monolithic kernel (which means that user processes carried out kernel system calls all on the user stack). If a signal was delivered to a process while it was blocked on a long-term I/O in the kernel, then what should be done? Should the signal be delayed, possibly for a long time (maybe indefinitely) while the I/O completed? The signal handler could not be executed when the process was in kernel mode, with sensitive kernel data on the stack. Should the kernel back-out the system call, and store it, for replay and restart later, assuming that the signal handler completes successfully?

 

In these cases Ken Thompson and Dennis Ritchie favored simplicity over perfection. The UNIX system would occasionally return early from a system call with an error stating that it had done nothing - the "Interrupted System Call" - an error number 4 (EINTR) in today's systems. Of course the call had been aborted in order to call the signal handler. This could only happen for a handful of long-running system calls, i.e. read(), write(), open(), select(), etc. On the plus side, this made the I/O system many times simpler to design and understand. The vast majority of user programs were never affected because they didn't handle or experience signals other than SIGINT/^C and would die right away if one was raised. For the few other programs - things like shells or text editors that respond to job control keypresses - small wrappers could be added to system calls so as to retry the call right away if this EINTR error was raised. Problem solved, in a simple way.

更过Unix哲学,请看:http://en.wikipedia.org/wiki/Unix_philosophy

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值