代码改变世界

随笔分类 -  Linux/Unix

[转] Real-World Concurrency

2011-03-15 13:37 by zhenjing, 538 阅读, 收藏, 编辑
摘要: 1. Know your cold paths from your hot paths. 弄清楚代码里的热门执行路径和冷门执行路径。 2. Intuition is frequently wrong—be data intensive. 直觉常常是错的,要靠数据说话。 3. Know when—and when not—to break up a lock. 知道什么时候把一个锁拆成多个,并知道什么时候不必这样做。 4. Be wary of readers/writer locks. 警惕读写锁。 5. Consider per-CPU locking. 考虑用每个 CPU 用一个锁。 6. Know when to broadcast—and when to signal. 知道什么时候用单个唤醒,什么时候用广播唤醒。 7. Learn to debug postmortem. 学会验尸 8. Design your systems to be composable. 设计系统(s),使之能相互组合。 9. Don’t use a semaphore where a 阅读全文

[转] Buffer Overflows and You (下)

2011-03-03 11:59 by zhenjing, 809 阅读, 收藏, 编辑
摘要: Got root?Gentlemen, we can root it. We have the technology. We have the capability to root yet another poor idiot's server on the int4rw3bs. Steve Austin will be that man. Better than he was before. Better, stronger, faster, errrr...We spent all that time developing a small bit of shellcode. Let 阅读全文

[转] Buffer Overflows and You (上)

2011-03-03 11:48 by zhenjing, 788 阅读, 收藏, 编辑
摘要: Magical gnomes present: Buffer Overflows and You Is it the 90's? Are you wondering why your server is running slow? Why it's trying to ping flood some host in California? Why someone else is logged into your machine and you've recently become a prominent porn hosting provider? This site will help you figure it all out. And if you have a time machine, you can probably go back and do it to someone else! Before continuing, it's important to note that this guide is designed for 64-bit systems. 阅读全文

How to create a size-limited file-system

2011-01-18 15:57 by zhenjing, 427 阅读, 收藏, 编辑
摘要: 在特定情况下(如测试),需要建立大小受限的文件夹,最简单的办法莫过于使用linux提供的Loopback设备。Loopback文件系统就是把一个文件和另外的一个文件系统联系起来,就像一个完整文件系统一样。它可以被格式化和mount成以上所提到过的文件系统。这样,这些设备就被称为/dev/loop0或者/dev/loop1,然后和文件产生联系,然后这个虚拟设备被mount。 阅读全文

Condition Variables(条件变量)用法指南

2010-12-30 12:01 by zhenjing, 3027 阅读, 收藏, 编辑
摘要: 详细介绍Linux/Unix下condition variable(条件变量)的用法:pthread_cond_timedwait,pthread_cond_wait, pthread_cond_broadcast, pthread_cond_signal。 同时介绍了Condition variable and thread cancellation, Condition variable and signal, Condition variable and signal handler. 阅读全文

pthread_atfork用法

2010-12-28 12:05 by zhenjing, 4073 阅读, 收藏, 编辑
摘要: pthread_atfork的manual。虽然pthread_atfork无法解决多线程下fork的所有问题,但仍然是减少fork死锁的工具,尤其适用于库的编写,即:多线程库应该有意地提供接口以获取所有的锁以及释放它们(锁最好有粒度区别) 阅读全文

Thread Cancel 指南

2010-12-27 11:59 by zhenjing, 2034 阅读, 收藏, 编辑
摘要: 详细介绍与线程取消(cancel)相关的编程接口:pthread_cancel,pthread_setcancelstate,pthread_setcanceltype, pthread_cleanup_pop,pthread_cleanup_push,pthread_join,pthread_detach 阅读全文

UNIX上C++程序设计守则(信号和线程)(下)

2010-12-23 12:01 by zhenjing, 8047 阅读, 收藏, 编辑
摘要: 准则4: 请不要做线程的异步撤消的设计; 准则5: 尽可能避免线程中做延迟撤销的处理; 准则6: 遵守多线程编程的常识 阅读全文

UNIX上C++程序设计守则(信号和线程)(上)

2010-12-22 12:00 by zhenjing, 3140 阅读, 收藏, 编辑
摘要: Unix/Linux编写程序离不开信号、多进程/多线程,尤其是编写服务器程序。然而正确编写多进程/多线程程序是很难的事情。难不在于写出可工作的程序,而在于写出持续工作的程序。这篇文章是转载,关于这个话题,这是本人见过的最好的文章。推荐之。准则1:不依赖于信号收发的设计;准则2: 要知道信号处理函数中可以做那些处理;准则3:多线程程序里不准使用fork 阅读全文

Usage of Protocol Buffer

2010-11-15 23:01 by zhenjing, 2828 阅读, 收藏, 编辑
摘要: Protocol Buffer简单学习教程。去年用过Protocol Buffer后,写下的总结,应该有助于快速上手。 阅读全文

Linux Debug tools

2010-10-27 11:47 by zhenjing, 3361 阅读, 收藏, 编辑
摘要: 虽然搞了Unix/Linux的分类,却一直没有发表相关的随笔。这算第一篇吧。经验有限,欢迎补充! 阅读全文