看板FreeBSD
标 题Re: mrtg怎麽抓bbs的上线人数?
发信站东海大度山之恋 BBS 站 (Fri Apr 16 01:49:33 2004)
转信站ptt!ctu-reader!ctu-peer!news.nctu!news.cis.nctu!dadusan
【 在
[email protected] (家产有八十七亿) 的大作中提到: 】
: 是不是应该抓目前有几个mbbsd process??
: 该怎麽做呢?? thanks~
这样其实不是很精准
因为会有的人开到进站画面 但还没login
process 已经产生了 , 但是他还不算是已经登入的user ...
精确的作法应该是扫一遍 shared memory ...或抓 shm 中存目前人数的值 ...
这部份各 bbs 的作法就不太一样了 ,
以 PTT 为例 , 程式大概类似这样
(我用的是很早期的 PTT 版本, 现在的版本不知道需不需要修改就是了 ... )
===========================================================================
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <machine/param.h>
#include "config.h"
#include "struct.h"
struct utmpfile_t *utmpshm;
void attach_err()
{
perror("attach shared memory error!!\n");
}
void *attach_shm( int key, int shmsize )
{
void *shmptr;
int shmid;
shmid = shmget( key, shmsize, 0 );
if( shmid < 0 ) {
attach_err();
exit( -1 );
}
else {
shmptr = (void *) shmat( shmid, NULL, 0 );
if( shmptr == (void *)-1 ) {
attach_err();
exit( -1 );
}
}
return shmptr;
}
int main()
{
utmpshm = attach_shm( UTMPSHM_KEY, sizeof( *utmpshm ) );
printf("%d\n", utmpshm->number );
return 0;
}
===========================================================================
--
※ 来源:‧大度山之恋 bbs.thu.edu.tw‧[FROM: 220-134-60-125.]