Archive for三月 31, 2005

借了几本书

早上一二节没课,难得早起,去图书馆借书,其实也不知道自己要找什么书.
只是前几天糊里糊涂把 POSIX程序员指南给还了,昨天突然想起有用,一定
要把它搞回来的,西文书库的书一般只有一本,万一被别人借去就不好了.

顺便借了一本 BSD4.4操作系统设计与实现中文版 ,浙大的几位教授翻译的,
翻了翻,感觉翻得不错,至少不像APUE那么烂,而且对名字都加上了英文标记.

近期的目标是熟悉Unix 环境下的编程,刚才laoz 发信给我说科研项目挂了.
对我倒是一种解脱,确实对那个项目没什么兴趣,我是实话实说.不用去做
不感兴趣的事情,实在是件令人高兴的事情.

下午是数据结构上机,本想把第二个题目编编看的,但不论如何也提不起精神
对这种垃圾程序有点不屑,发自内心的,宁愿浪费时间坐着也不想动,况且还
要帮别人改程序,而帮助别人我是很乐意的.

算了,实在不行就抄吧.

晚上去看了下 枫林在线 bbs ,它在网页转信和BBS数据的XML化方面已经做
得很成熟了,而我们却还是种设想. 源码是公开的,但 cvs 登录不上去,可能
是CVS服务器挂掉了,但不管怎么说,总算是证明这种想法是可行的,而且别人
已经有了实现,今后的工作可以轻松一点.

在145上把 sshbbsd 配置好了,端口开在2222 上,不禁感叹,开源真是一种完
美的设想,SMTH 仅仅修改了下 sshd的几处接口就实现了 sshbbsd,感谢开源精神.

如果端口允许的话,我想FQYY主站开SSHBBSD也是十分必要的,这对数据和通讯保密
十分有好处.

Comments (3)

doc/userid

//hash 命中liu 是1.6 ,不知道是个什么意思..好好学学.

用户hash设计

——————————————————————————–

firebird BBS系统查询用户一直使用的是从头到尾遍历整个用户链表的模式
来查找用户,这个在大用户量的情况下是极大的开销。为了解决这个问题,
我设想使用hash表保存用户id索引,加快查找速度。相关的程序在libBBS/ucache.c
和libBBS/utmp.c中实现。
这个函数由我和ttiny@SMTH共同设计,由ttiny@SMTH完成。
我采用的是线性探测再散列的hash表。之所以不用二次探测再散列,是考虑到
当我们的hash_size>2-3倍的max_user的时候,如果选择恰当的hash函数,hash
的命中率可以 0 –
1 1 |
2 ———> 2 |
4

Comments (1)

昨天看书时发现的

daemon_init() function

daemon_init()
{
int i ;
pid_t pid;
if(pid=fork())
exit(0);

setsid();

signal(SIGHUP,SIG_IGN);

if(pid=fork())
exit(0)

}

解释 ,摘自 UNP 368-369 页:

We first call fork and the parent terminates ,and the child continues.
If the process was started as a shell command in the foreground ,when the
parent terminates ,the shell thinks the command is done.This automatially runs
the child process in the backgroud .

setsid is a POSIX function that creates a new session . The process becomes the
session leader of the new session ,becomes the process group leader of a new
process group and has no controlling terminal .

Ignore SIGHUP and fork again
We ignore SIGHUP and call fork again .When this function returns ,the parent
is really the first child and it terminates ,leaving the second child running.
The purpose of thies second fork is to guarantee that the daemon cannot
automatically acquire a controlling terminal should it open a terminal device
in the future. By calling fork a second time ,we guarantee that the second child
is no longer a session leader ,so it cannot acquire a controlling terminal .
We must ignore SIGHUP because whe the session leader terminates(the first child)
,all processs in the session(our second child) receive SIGHUP signal

评论