锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久99精品国产麻豆蜜芽,久久亚洲精品无码播放,日韩欧美亚洲国产精品字幕久久久http://www.shnenglu.com/bujiwu/zh-cnWed, 07 May 2025 19:09:31 GMTWed, 07 May 2025 19:09:31 GMT60Linux鍐呮牳VFS---rootfs鏂囦歡緋葷粺鍔犺澆http://www.shnenglu.com/bujiwu/archive/2010/07/04/119301.htmlbujiwubujiwuSun, 04 Jul 2010 08:58:00 GMThttp://www.shnenglu.com/bujiwu/archive/2010/07/04/119301.htmlhttp://www.shnenglu.com/bujiwu/comments/119301.htmlhttp://www.shnenglu.com/bujiwu/archive/2010/07/04/119301.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/119301.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/119301.html
1.鍐呮牳鍚姩璋冪敤start_kernel鍑芥暟榪涜鍒濆鍖栥?
asmlinkage void __init start_kernel(void//init\Main.c:528
{
    buffer_init();
    key_init();
    security_init();
    vfs_caches_init(totalram_pages);
//678琛岋紝vfs鍒濆鍖?/span>
    signals_init();
}
2.start_kernel璋冪敤vfs_caches_init瀵箆fs榪涜鍒濆鍖栥?br>
//fs\Dcach.c:2354琛?/span>
void __init vfs_caches_init(unsigned long mempages)
{
   
.......
    dcache_init();
    inode_init();
    files_init(mempages);
    mnt_init(); 
//mnt鍒濆鍖?/span>
    bdev_cache_init();
    chrdev_init();
}

3.鍦╲fs_caches_init璋冪敤fs\namespace.c 2321琛岀殑mnt_init鍑芥暟
void __init mnt_init(void)
{
    
    init_rootfs();    
//鍒濆鍖杛ootfs鏂囦歡緋葷粺
    init_mount_tree(); //鍒濆鍖栧姞杞芥爲(wèi)
}
4. fs\ramfs絎?08琛岀殑init_rootfs鍑芥暟鍒濆鍖杛ootfs鏂囦歡緋葷粺
int __init init_rootfs(void)
{
    
int err;

    err 
= bdi_init(&ramfs_backing_dev_info);
    
if (err)
        
return err;

    err 
= register_filesystem(&rootfs_fs_type);//娉ㄥ唽rootfs鏂囦歡緋葷粺
    if (err)
        bdi_destroy(
&ramfs_backing_dev_info);

    
return err;
}
rootfs鏂囦歡緋葷粺淇℃伅fs\ramfs絎?89琛?
static struct file_system_type rootfs_fs_type = {
    .name        
= "rootfs",
    .get_sb        
= rootfs_get_sb,
    .kill_sb    
= kill_litter_super,
};

5.璋冪敤register_filesystem鍑芥暟灝唕ootfs娉ㄥ唽鍒?span style="font-weight: bold; color: #ff0000; font-family: 榛戜綋;">file_systems鏂囦歡緋葷粺涓?br>
//fs\Filesystem.c絎?9琛屻?br>int register_filesystem(struct file_system_type * fs)
{
    
int res = 0;
    
struct file_system_type ** p;

    BUG_ON(strchr(fs
->name, '.'));
    
if (fs->next)
        
return -EBUSY;
    INIT_LIST_HEAD(
&fs->fs_supers);
    write_lock(
&file_systems_lock);
    p 
= find_filesystem(fs->name, strlen(fs->name));//鏌ユ壘鍒版枃浠剁郴緇熷姞杞戒綅緗?br>    if (*p)
        res 
= -EBUSY;
    
else
        
*= fs;
    write_unlock(
&file_systems_lock);
    
return res;
}
file_systems鍙橀噺鏄墍鏈夋枃浠剁郴緇熼摼琛ㄧ殑澶存寚閽堛傞氳繃浠ヤ笂榪囩▼rootfs_fs_type灝卞姞鍏ュ埌浜?jiǎn)file_systems閾捐〃澶寸殑file_system_type綾誨瀷鐨勯摼琛ㄤ腑銆傚彲浠ラ氳繃file_systems鎸囬拡閬嶅巻榪欎釜閾捐〃錛屽緱鍒扮壒瀹氱殑鏂囦歡緋葷粺file_system_type 鎸囬拡銆?br>

bujiwu 2010-07-04 16:58 鍙戣〃璇勮
]]>
[杞澆]top鍛戒護(hù)璇﹁Вhttp://www.shnenglu.com/bujiwu/archive/2010/04/27/top.htmlbujiwubujiwuTue, 27 Apr 2010 05:26:00 GMThttp://www.shnenglu.com/bujiwu/archive/2010/04/27/top.htmlhttp://www.shnenglu.com/bujiwu/comments/113700.htmlhttp://www.shnenglu.com/bujiwu/archive/2010/04/27/top.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/113700.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/113700.htmlhttp://blog.chinaunix.net/u/12973/showart_637900.html


top鍛戒護(hù)鏄疞inux涓嬪父鐢ㄧ殑鎬ц兘鍒嗘瀽宸ュ叿錛岃兘澶熷疄鏃舵樉紺虹郴緇熶腑鍚勪釜榪涚▼鐨勮祫婧愬崰鐢ㄧ姸鍐碉紝綾諱技浜嶹indows鐨勪換鍔$鐞嗗櫒銆備笅闈㈣緇嗕粙緇嶅畠鐨勪嬌鐢ㄦ柟娉曘?

top - 01:06:48 up  1:22,  1 user,  load average: 0.06, 0.60, 0.48
Tasks:  29 total,   1 running,  28 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3% us,  1.0% sy,  0.0% ni, 98.7% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:    191272k total,   173656k used,    17616k free,    22052k buffers
Swap:   192772k total,        0k used,   192772k free,   123988k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  1379 root      16   0  7976 2456 1980 S  0.7  1.3   0:11.03 sshd
14704 root      16   0  2128  980  796 R  0.7  0.5   0:02.72 top
     1 root      16   0  1992  632  544 S  0.0  0.3   0:00.90 init
     2 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0

緇熻淇℃伅鍖?/h4>

鍓嶄簲琛屾槸緋葷粺鏁翠綋鐨勭粺璁′俊鎭傜涓琛屾槸浠誨姟闃熷垪淇℃伅錛屽悓 uptime 鍛戒護(hù)鐨勬墽琛岀粨鏋溿傚叾鍐呭濡備笅錛?/p>

01:06:48 褰撳墠鏃墮棿
up 1:22 緋葷粺榪愯鏃墮棿錛屾牸寮忎負(fù)鏃?鍒?/td>
1 user 褰撳墠鐧誨綍鐢ㄦ埛鏁?/td>
load average: 0.06, 0.60, 0.48 緋葷粺璐熻澆錛屽嵆浠誨姟闃熷垪鐨勫鉤鍧囬暱搴︺?br> 涓変釜鏁板煎垎鍒負(fù) 1鍒嗛挓銆?鍒嗛挓銆?5鍒嗛挓鍓嶅埌鐜板湪鐨勫鉤鍧囧箋?/td>

絎簩銆佷笁琛屼負(fù)榪涚▼鍜孋PU鐨勪俊鎭傚綋鏈夊涓狢PU鏃訛紝榪欎簺鍐呭鍙兘浼?xì)瓒厴q囦袱琛屻傚唴瀹瑰涓嬶細(xì)

Tasks: 29 total 榪涚▼鎬繪暟
1 running 姝e湪榪愯鐨勮繘紼嬫暟
28 sleeping 鐫$湢鐨勮繘紼嬫暟
0 stopped 鍋滄鐨勮繘紼嬫暟
0 zombie 鍍靛案榪涚▼鏁?/td>
Cpu(s): 0.3% us 鐢ㄦ埛絀洪棿鍗犵敤CPU鐧懼垎姣?/td>
1.0% sy 鍐呮牳絀洪棿鍗犵敤CPU鐧懼垎姣?/td>
0.0% ni 鐢ㄦ埛榪涚▼絀洪棿鍐呮敼鍙樿繃浼樺厛綰х殑榪涚▼鍗犵敤CPU鐧懼垎姣?/td>
98.7% id 絀洪棽CPU鐧懼垎姣?/td>
0.0% wa 絳夊緟杈撳叆杈撳嚭鐨凜PU鏃墮棿鐧懼垎姣?/td>
0.0% hi  
0.0% si  

鏈鍚庝袱琛屼負(fù)鍐呭瓨淇℃伅銆傚唴瀹瑰涓嬶細(xì)

Mem: 191272k total 鐗╃悊鍐呭瓨鎬婚噺
173656k used 浣跨敤鐨勭墿鐞嗗唴瀛樻婚噺
17616k free 絀洪棽鍐呭瓨鎬婚噺
22052k buffers 鐢ㄤ綔鍐呮牳緙撳瓨鐨勫唴瀛橀噺
Swap: 192772k total 浜ゆ崲鍖烘婚噺
0k used 浣跨敤鐨勪氦鎹㈠尯鎬婚噺
192772k free 絀洪棽浜ゆ崲鍖烘婚噺
123988k cached 緙撳啿鐨勪氦鎹㈠尯鎬婚噺銆?br> 鍐呭瓨涓殑鍐呭琚崲鍑哄埌浜ゆ崲鍖猴紝鑰屽悗鍙堣鎹㈠叆鍒板唴瀛橈紝浣嗕嬌鐢ㄨ繃鐨勪氦鎹㈠尯灝氭湭琚鐩栵紝
璇ユ暟鍊煎嵆涓鴻繖浜?strong>鍐呭宸插瓨鍦ㄤ簬鍐呭瓨涓?/strong>鐨勪氦鎹㈠尯鐨勫ぇ灝忋?br> 鐩稿簲鐨勫唴瀛樺啀嬈¤鎹㈠嚭鏃跺彲涓嶅繀鍐嶅浜ゆ崲鍖哄啓鍏ャ?/td>

榪涚▼淇℃伅鍖?/h4>

緇熻淇℃伅鍖哄煙鐨勪笅鏂規(guī)樉紺轟簡(jiǎn)鍚勪釜榪涚▼鐨勮緇嗕俊鎭傞鍏堟潵璁よ瘑涓涓嬪悇鍒楃殑鍚箟銆?/p>

搴忓彿 鍒楀悕 鍚箟
a PID 榪涚▼id
b PPID 鐖惰繘紼媔d
c RUSER Real user name
d UID 榪涚▼鎵鏈夎呯殑鐢ㄦ埛id
e USER 榪涚▼鎵鏈夎呯殑鐢ㄦ埛鍚?/td>
f GROUP 榪涚▼鎵鏈夎呯殑緇勫悕
g TTY 鍚姩榪涚▼鐨勭粓绔悕銆備笉鏄粠緇堢鍚姩鐨勮繘紼嬪垯鏄劇ず涓??
h PR 浼樺厛綰?/td>
i NI nice鍊箋傝礋鍊艱〃紺洪珮浼樺厛綰э紝姝e艱〃紺轟綆浼樺厛綰?/td>
j P 鏈鍚庝嬌鐢ㄧ殑CPU錛屼粎鍦ㄥCPU鐜涓嬫湁鎰忎箟
k %CPU 涓婃鏇存柊鍒扮幇鍦ㄧ殑CPU鏃墮棿鍗犵敤鐧懼垎姣?/td>
l TIME 榪涚▼浣跨敤鐨凜PU鏃墮棿鎬昏錛屽崟浣嶇
m TIME+ 榪涚▼浣跨敤鐨凜PU鏃墮棿鎬昏錛屽崟浣?/100縐?/td>
n %MEM 榪涚▼浣跨敤鐨?strong>鐗╃悊鍐呭瓨鐧懼垎姣?/td>
o VIRT 榪涚▼浣跨敤鐨勮櫄鎷熷唴瀛樻婚噺錛屽崟浣峩b銆俈IRT=SWAP+RES
p SWAP 榪涚▼浣跨敤鐨勮櫄鎷熷唴瀛樹腑錛岃鎹㈠嚭鐨勫ぇ灝忥紝鍗曚綅kb銆?/td>
q RES 榪涚▼浣跨敤鐨勩佹湭琚崲鍑虹殑鐗╃悊鍐呭瓨澶у皬錛屽崟浣峩b銆俁ES=CODE+DATA
r CODE 鍙墽琛屼唬鐮佸崰鐢ㄧ殑鐗╃悊鍐呭瓨澶у皬錛屽崟浣峩b
s DATA 鍙墽琛屼唬鐮佷互澶栫殑閮ㄥ垎(鏁版嵁孌?鏍?鍗犵敤鐨?strong>鐗╃悊鍐? 瀛樺ぇ灝忥紝鍗曚綅kb
t SHR 鍏變韓鍐呭瓨澶у皬錛屽崟浣峩b
u nFLT 欏甸潰閿欒嬈℃暟
v nDRT 鏈鍚庝竴嬈″啓鍏ュ埌鐜板湪錛岃淇敼榪囩殑欏甸潰鏁般?/td>
w S 榪涚▼鐘舵併?br> D=涓嶅彲涓柇鐨勭潯鐪犵姸鎬?br> R=榪愯
S=鐫$湢
T=璺熻釜/鍋滄
Z=鍍靛案榪涚▼
x COMMAND 鍛戒護(hù)鍚?鍛戒護(hù)琛?/td>
y WCHAN 鑻ヨ榪涚▼鍦ㄧ潯鐪狅紝鍒欐樉紺虹潯鐪犱腑鐨勭郴緇熷嚱鏁板悕
z Flags 浠誨姟鏍囧織錛屽弬鑰?sched.h

榛樿鎯呭喌涓嬩粎鏄劇ず姣旇緝閲嶈鐨?PID銆乁SER銆丳R銆丯I銆乂IRT銆丷ES銆丼HR銆丼銆?CPU銆?MEM銆乀IME+銆丆OMMAND 鍒椼傚彲浠ラ氳繃涓嬮潰鐨勫揩鎹烽敭鏉ユ洿鏀規(guī)樉紺哄唴瀹廣?/p>

鏇存敼鏄劇ず鍐呭

閫氳繃 f 閿彲浠ラ夋嫨鏄劇ず鐨勫唴瀹廣傛寜 f 閿箣鍚庝細(xì)鏄劇ず鍒楃殑鍒楄〃錛屾寜 a-z 鍗沖彲鏄劇ず鎴栭殣钘忓搴旂殑鍒楋紝鏈鍚庢寜鍥炶濺閿‘瀹氥?/p>

鎸?o 閿彲浠ユ敼鍙樺垪鐨勬樉紺洪『搴忋傛寜灝忓啓鐨?a-z 鍙互灝嗙浉搴旂殑鍒楀悜鍙崇Щ鍔紝鑰屽ぇ鍐欑殑 A-Z 鍙互灝嗙浉搴旂殑鍒楀悜宸︾Щ鍔ㄣ傛渶鍚庢寜鍥炶濺閿‘瀹氥?/p>

鎸夊ぇ鍐欑殑 F 鎴?O 閿紝鐒跺悗鎸?a-z 鍙互灝嗚繘紼嬫寜鐓х浉搴旂殑鍒楄繘琛屾帓搴忋傝屽ぇ鍐欑殑 R 閿彲浠ュ皢褰撳墠鐨勬帓搴忓掕漿銆?/p>

鍛戒護(hù)浣跨敤

1錛?宸ュ叿錛堝懡浠わ級(jí)鍚嶇О
top
2錛庡伐鍏鳳紙鍛戒護(hù)錛変綔鐢?br> 鏄劇ず緋葷粺褰撳墠鐨勮繘紼嬪拰鍏朵粬鐘跺喌錛? top鏄竴涓姩鎬佹樉紺鴻繃紼?鍗沖彲浠ラ氳繃鐢ㄦ埛鎸夐敭鏉ヤ笉鏂埛鏂板綋鍓嶇姸鎬?濡傛灉鍦ㄥ墠鍙版墽琛岃鍛戒護(hù),瀹冨皢鐙崰鍓嶅彴,鐩村埌鐢ㄦ埛緇堟璇ョ▼搴忎負(fù)姝? 姣旇緝鍑嗙‘鐨勮,top鍛戒護(hù)鎻愪緵浜?jiǎn)瀹炴椂鐨勫绯痪l熷鐞嗗櫒鐨勭姸鎬佺洃瑙?瀹冨皢鏄劇ず緋葷粺涓瑿PU鏈“鏁忔劅”鐨勪換鍔″垪琛?璇ュ懡浠ゅ彲浠ユ寜CPU浣跨敤.鍐呭瓨浣跨敤鍜屾墽琛屾椂闂? 瀵逛換鍔¤繘琛屾帓搴忥紱鑰屼笖璇ュ懡浠ょ殑寰堝鐗規(guī)ч兘鍙互閫氳繃浜や簰寮忓懡浠ゆ垨鑰呭湪涓漢瀹氬埗鏂囦歡涓繘琛岃瀹?
3錛庣幆澧冭緗?br> 鍦↙inux涓嬩嬌鐢ㄣ?br> 4錛庝嬌鐢ㄦ柟娉?br> 4錛?浣跨敤鏍煎紡
top [-] [d] [p] [q] [c] [C] [S] [s]  [n]
4錛?鍙傛暟璇存槑
 d 鎸囧畾姣忎袱嬈″睆騫曚俊鎭埛鏂頒箣闂寸殑鏃墮棿闂撮殧銆傚綋鐒剁敤鎴峰彲浠ヤ嬌鐢╯浜や簰鍛戒護(hù)鏉ユ敼鍙樹箣銆?br>  p 閫氳繃鎸囧畾鐩戞帶榪涚▼ID鏉ヤ粎浠呯洃鎺ф煇涓繘紼嬬殑鐘舵併?br>  q璇ラ夐」灝嗕嬌top娌℃湁浠諱綍寤惰繜鐨勮繘琛屽埛鏂般傚鏋滆皟鐢ㄧ▼搴忔湁瓚呯駭鐢ㄦ埛鏉冮檺錛岄偅涔坱op灝嗕互 灝藉彲鑳介珮鐨勪紭鍏堢駭榪愯銆?br>  S 鎸囧畾绱妯″紡
 s 浣縯op鍛戒護(hù)鍦ㄥ畨鍏ㄦā寮忎腑榪愯銆傝繖灝嗗幓闄や氦浜掑懡浠ゆ墍甯︽潵鐨勬綔鍦ㄥ嵄闄┿?br>  i  浣縯op涓嶆樉紺轟換浣曢棽緗垨鑰呭兊姝昏繘紼嬨?br>  c  鏄劇ず鏁翠釜鍛戒護(hù)琛岃屼笉鍙槸鏄劇ず鍛戒護(hù)鍚?br> 4.3鍏朵粬
涓嬮潰浠嬬粛鍦╰op鍛戒護(hù)鎵ц榪囩▼涓彲浠ヤ嬌鐢ㄧ殑涓浜涗氦浜掑懡浠ゃ備粠浣跨敤瑙掑害鏉ョ湅錛岀啛緇冪殑鎺屾彙榪欎簺鍛戒護(hù)姣旀帉鎻¢夐」榪橀噸瑕佷竴浜涖傝繖浜涘懡浠ら兘鏄崟瀛楁瘝鐨勶紝濡傛灉鍦ㄥ懡 浠よ閫夐」涓嬌鐢ㄤ簡(jiǎn)s閫夐」錛屽垯鍙兘鍏朵腑涓浜涘懡浠や細(xì)琚睆钄芥帀銆?br> Ctrl+L 鎿﹂櫎騫朵笖閲嶅啓灞忓箷銆?br> h鎴栬? 鏄劇ず甯姪鐢婚潰錛岀粰鍑轟竴浜涚畝鐭殑鍛戒護(hù)鎬葷粨璇存槑銆?br> k 緇堟涓涓繘紼嬨傜郴緇熷皢鎻愮ず鐢ㄦ埛杈撳叆闇瑕佺粓姝㈢殑榪涚▼PID錛屼互鍙?qiáng)闇瑕佸彂閫佺粰璇ヨ繘紼嬩粈涔堟牱鐨勪俊鍙楓備竴鑸殑緇堟榪涚▼鍙互浣跨敤15淇″彿錛涘鏋滀笉鑳芥甯哥粨鏉熼偅灝變嬌鐢? 淇″彿9寮哄埗緇撴潫璇ヨ繘紼嬨傞粯璁ゅ兼槸淇″彿15銆傚湪瀹夊叏妯″紡涓鍛戒護(hù)琚睆钄姐?br> i 蹇界暐闂茬疆鍜屽兊姝昏繘紼嬨傝繖鏄竴涓紑鍏沖紡鍛戒護(hù)銆?br> q 閫鍑虹▼搴忋?br> r 閲嶆柊瀹夋帓涓涓繘紼嬬殑浼樺厛綰у埆銆傜郴緇熸彁紺虹敤鎴瘋緭鍏ラ渶瑕佹敼鍙樼殑榪涚▼PID浠ュ強(qiáng)闇瑕佽緗殑 榪涚▼浼樺厛綰у箋傝緭鍏ヤ竴涓鍊煎皢浣夸紭鍏堢駭闄嶄綆錛屽弽涔嬪垯鍙互浣胯榪涚▼鎷ユ湁鏇撮珮鐨勪紭鍏堟潈銆傞粯璁ゅ兼槸10銆?br> S 鍒囨崲鍒扮瘡璁℃ā寮忋?br> s 鏀瑰彉涓ゆ鍒鋒柊涔嬮棿鐨勫歡榪熸椂闂淬傜郴緇熷皢鎻愮ず鐢ㄦ埛杈撳叆鏂扮殑鏃墮棿錛屽崟浣嶄負(fù)s銆傚鏋滄湁灝忔暟錛? 灝辨崲綆楁垚m s銆傝緭鍏?鍊煎垯緋葷粺灝嗕笉鏂埛鏂幫紝榛樿鍊兼槸5 s銆傞渶瑕佹敞鎰忕殑鏄鏋滆緗お灝忕殑鏃墮棿錛屽緢鍙兘浼?xì)寮曡捣涓嶆柇鍒锋枎图屼粠鑰屾牴鏈潵涓嶅強(qiáng)鐪嬫竻鏄劇ず鐨勬儏鍐碉紝鑰屼笖緋葷粺璐熻澆涔熶細(xì)澶уぇ澧炲姞銆?br> f鎴栬匜 浠庡綋鍓嶆樉紺轟腑娣誨姞鎴栬呭垹闄ら」鐩?br> o鎴栬匫 鏀瑰彉鏄劇ず欏圭洰鐨勯『搴忋?br> l 鍒囨崲鏄劇ず騫沖潎璐熻澆鍜屽惎鍔ㄦ椂闂翠俊鎭?br> m 鍒囨崲鏄劇ず鍐呭瓨淇℃伅銆?br> t 鍒囨崲鏄劇ず榪涚▼鍜孋PU鐘舵佷俊鎭?br> c 鍒囨崲鏄劇ず鍛戒護(hù)鍚嶇О鍜屽畬鏁村懡浠よ銆?br> 銆M 鏍規(guī)嵁椹葷暀鍐呭瓨澶у皬榪涜鎺掑簭銆?br> P 鏍規(guī)嵁CPU浣跨敤鐧懼垎姣斿ぇ灝忚繘琛屾帓搴忋?br> T 鏍規(guī)嵁鏃墮棿/绱鏃墮棿榪涜鎺掑簭銆?br>     W 灝嗗綋鍓嶈緗啓鍏/.toprc鏂囦歡涓傝繖鏄啓top閰嶇疆鏂囦歡鐨勬帹鑽愭柟娉曘?/span>





bujiwu 2010-04-27 13:26 鍙戣〃璇勮
]]>
[杞澆]C鍑芥暟atoi鐨勫疄鐜?/title><link>http://www.shnenglu.com/bujiwu/archive/2010/01/15/atoi.html</link><dc:creator>bujiwu</dc:creator><author>bujiwu</author><pubDate>Fri, 15 Jan 2010 09:52:00 GMT</pubDate><guid>http://www.shnenglu.com/bujiwu/archive/2010/01/15/atoi.html</guid><wfw:comment>http://www.shnenglu.com/bujiwu/comments/105772.html</wfw:comment><comments>http://www.shnenglu.com/bujiwu/archive/2010/01/15/atoi.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bujiwu/comments/commentRss/105772.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bujiwu/services/trackbacks/105772.html</trackback:ping><description><![CDATA[杞澆閾炬帴:<a >http://blog.chinaunix.net/u2/76292/showart_1845022.html</a><br><br> <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;"> 1</span> <span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">stdlib.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 2</span> <span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">stdio.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 3</span> <span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">ctype.h</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 4</span> <span style="color: #000000;"><br></span><span style="color: #008080;"> 5</span> <span style="color: #000000;"></span><span style="color: #0000ff;">long</span><span style="color: #000000;"> my_atol(</span><span style="color: #0000ff;">const</span><span style="color: #000000;"> </span><span style="color: #0000ff;">char</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;">nptr)<br></span><span style="color: #008080;"> 6</span> <span style="color: #000000;">{<br></span><span style="color: #008080;"> 7</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> c; </span><span style="color: #008000;">/*</span><span style="color: #008000;"> current char </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;"> 8</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">long</span><span style="color: #000000;"> total; </span><span style="color: #008000;">/*</span><span style="color: #008000;"> current total </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;"> 9</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> sign; </span><span style="color: #008000;">/*</span><span style="color: #008000;"> if '-', then negative, otherwise positive </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">10</span> <span style="color: #000000;"><br></span><span style="color: #008080;">11</span> <span style="color: #000000;">    </span><span style="color: #008000;">/*</span><span style="color: #008000;"> skip whitespace </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">12</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> ( isspace((</span><span style="color: #0000ff;">int</span><span style="color: #000000;">)(unsigned </span><span style="color: #0000ff;">char</span><span style="color: #000000;">)</span><span style="color: #000000;">*</span><span style="color: #000000;">nptr) )<br></span><span style="color: #008080;">13</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">14</span> <span style="color: #000000;">        </span><span style="color: #000000;">++</span><span style="color: #000000;">nptr;<br></span><span style="color: #008080;">15</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">16</span> <span style="color: #000000;">    <br></span><span style="color: #008080;">17</span> <span style="color: #000000;">    c </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #0000ff;">int</span><span style="color: #000000;">)(unsigned </span><span style="color: #0000ff;">char</span><span style="color: #000000;">)</span><span style="color: #000000;">*</span><span style="color: #000000;">nptr</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">18</span> <span style="color: #000000;">    sign </span><span style="color: #000000;">=</span><span style="color: #000000;"> c; </span><span style="color: #008000;">/*</span><span style="color: #008000;"> save sign indication </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">19</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (c </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">-</span><span style="color: #000000;">'</span><span style="color: #000000;"> </span><span style="color: #000000;">||</span><span style="color: #000000;"> c </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">+</span><span style="color: #000000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">20</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">21</span> <span style="color: #000000;">        c </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #0000ff;">int</span><span style="color: #000000;">)(unsigned </span><span style="color: #0000ff;">char</span><span style="color: #000000;">)</span><span style="color: #000000;">*</span><span style="color: #000000;">nptr</span><span style="color: #000000;">++</span><span style="color: #000000;">; </span><span style="color: #008000;">/*</span><span style="color: #008000;"> skip sign </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">22</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">23</span> <span style="color: #000000;">    <br></span><span style="color: #008080;">24</span> <span style="color: #000000;">    total </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">25</span> <span style="color: #000000;"><br></span><span style="color: #008080;">26</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> (isdigit(c)) <br></span><span style="color: #008080;">27</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">28</span> <span style="color: #000000;">        total </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">10</span><span style="color: #000000;"> </span><span style="color: #000000;">*</span><span style="color: #000000;"> total </span><span style="color: #000000;">+</span><span style="color: #000000;"> (c </span><span style="color: #000000;">-</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">0</span><span style="color: #000000;">'</span><span style="color: #000000;">); </span><span style="color: #008000;">/*</span><span style="color: #008000;"> accumulate digit </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">29</span> <span style="color: #000000;">        c </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #0000ff;">int</span><span style="color: #000000;">)(unsigned </span><span style="color: #0000ff;">char</span><span style="color: #000000;">)</span><span style="color: #000000;">*</span><span style="color: #000000;">nptr</span><span style="color: #000000;">++</span><span style="color: #000000;">; </span><span style="color: #008000;">/*</span><span style="color: #008000;"> get next char </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">30</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">31</span> <span style="color: #000000;"><br></span><span style="color: #008080;">32</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (sign </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">'</span><span style="color: #000000;">-</span><span style="color: #000000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">33</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">34</span> <span style="color: #000000;">       </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">total;<br></span><span style="color: #008080;">35</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">36</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">37</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">38</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> total; </span><span style="color: #008000;">/*</span><span style="color: #008000;"> return result, negated if necessary </span><span style="color: #008000;">*/</span><span style="color: #000000;"><br></span><span style="color: #008080;">39</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">40</span> <span style="color: #000000;">}<br></span><span style="color: #008080;">41</span> <span style="color: #000000;"><br></span><span style="color: #008080;">42</span> <span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;">  main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> argc, </span><span style="color: #0000ff;">char</span><span style="color: #000000;">*</span><span style="color: #000000;"> argv[])<br></span><span style="color: #008080;">43</span> <span style="color: #000000;">{<br></span><span style="color: #008080;">44</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">if</span><span style="color: #000000;">( argc </span><span style="color: #000000;"><</span><span style="color: #000000;"> </span><span style="color: #000000;">2</span><span style="color: #000000;"> )<br></span><span style="color: #008080;">45</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">46</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">;<br></span><span style="color: #008080;">47</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">48</span> <span style="color: #000000;"><br></span><span style="color: #008080;">49</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> i </span><span style="color: #000000;">=</span><span style="color: #000000;"> my_atol(argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">]);<br></span><span style="color: #008080;">50</span> <span style="color: #000000;">    printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">[%s]====>[%d]\n</span><span style="color: #000000;">"</span><span style="color: #000000;">, argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">], i);<br></span><span style="color: #008080;">51</span> <span style="color: #000000;">   <br></span><span style="color: #008080;">52</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> j </span><span style="color: #000000;">=</span><span style="color: #000000;"> atoi(argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">]);<br></span><span style="color: #008080;">53</span> <span style="color: #000000;">    printf(</span><span style="color: #000000;">"</span><span style="color: #000000;">[%s]====>[%d]\n</span><span style="color: #000000;">"</span><span style="color: #000000;">, argv[</span><span style="color: #000000;">1</span><span style="color: #000000;">], j);<br></span><span style="color: #008080;">54</span> <span style="color: #000000;"><br></span><span style="color: #008080;">55</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">56</span> <span style="color: #000000;">}<br></span><span style="color: #008080;">57</span> <span style="color: #000000;"></span></div> <a href="http://www.shnenglu.com/Files/bujiwu/atoi.rar">http://www.shnenglu.com/Files/bujiwu/atoi.rar</a><br><br><img src ="http://www.shnenglu.com/bujiwu/aggbug/105772.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bujiwu/" target="_blank">bujiwu</a> 2010-01-15 17:52 <a href="http://www.shnenglu.com/bujiwu/archive/2010/01/15/atoi.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Unix Network Programming - Vol2 璇諱功絎旇(Chapter 9. Record Locking)http://www.shnenglu.com/bujiwu/archive/2009/12/18/103474.htmlbujiwubujiwuFri, 18 Dec 2009 07:57:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/12/18/103474.htmlhttp://www.shnenglu.com/bujiwu/comments/103474.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/12/18/103474.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/103474.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/103474.html
#include <sys/types.h>
#include 
<errno.h>
#include 
<fcntl.h>
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<unistd.h>

#define FILE_PATH   "LockFile.txt"
#define MAXLINE     4096    /* max text line length */
#define FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

int LockSet(int fd, int Type)
{
    
struct flock lock;

    
lock.l_type = Type;        /* F_RDLCK, F_WRLCK, F_UNLCK */
    
lock.l_start = 0;          /* byte offset, relative to l_whence */
    
lock.l_whence = SEEK_END;  /* SEEK_SET, SEEK_CUR, SEEK_END */
    
lock.l_len = 0;            /* #bytes (0 means to EOF) */

    
return fcntl( fd, F_SETLK, &lock);
}

int main(int argc, char **argv)
{
    
char line[MAXLINE] = {0};

    
int fd = open(FILE_PATH, O_RDWR | O_CREAT| O_APPEND , FILE_MODE);

    
if ( LockSet(fd, F_WRLCK) < 0 )
    {
        
if (errno == EACCES || errno == EAGAIN)
        {
            printf(
"This program has running!\n");
            close(fd);
        }
        
else
        {
            printf(
"call fcntl function error.%s\n", strerror(errno) );
        }

        exit(
1);
    }

    printf(
"lock file [%s] successful\n", FILE_PATH);

    snprintf(line, 
sizeof(line), "%ld\n", (long) getpid());

    lseek(fd, 
0, SEEK_END);
    write(fd, line, strlen(line));

    getchar();

    
if ( LockSet(fd, F_UNLCK) < 0 )
    {
        printf(
"call fcntl function error.%s\n", strerror(errno) );
    }

    close(fd);

    
return 0;
}
http://www.shnenglu.com/Files/bujiwu/RecordLocking.rar



bujiwu 2009-12-18 15:57 鍙戣〃璇勮
]]>
boost::filestream緇勪歡灝佽http://www.shnenglu.com/bujiwu/archive/2009/11/23/101692.htmlbujiwubujiwuMon, 23 Nov 2009 05:44:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/23/101692.htmlhttp://www.shnenglu.com/bujiwu/comments/101692.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/23/101692.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/101692.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/101692.html
/*
 * @file FileSystem.h
 * @brief Operation file or diretory
 * @author Jiwu Bu
 * @version 1.0.0
 * @date 2009-11-23
 
*/
#ifndef FILESYSTEM_H_H
#define FILESYSTEM_H_H

#include 
<iostream>
#include 
<vector>

using namespace std;

class CFileSystem
{
public:
    
/*
     * @brief Gets an array of dirctories from current direcoty,
     *        using Recur value to determine whether to search 
     *        subdirectories.
     * @param SubDirVec Ouput parameter, return the search result
     * @param DirPath
     * @param Recur  Whether search subdirectories.
     * 
     * @return 
     
*/
    
static bool GetDirectories(vector<string>& SubDirVec, 
        
const string& DirPath, bool Recur = false);

    
/*
     * @brief Get the names of files in the specified directory that 
     *        match the specified extensive name, using a value to 
     *        determine whether to search subdirectories.
     * 
     * @param FileVec Ouput parameter, return the search result
     * @param DirPath
     * @param ExeName Extensive name, if ExeName equal  "*.*"  search all file
     * @param Recur   Whether search subdirectories
     * 
     * @return 
     
*/
    
static bool GetFiles(vector<string>& FileVec, const string& DirPath, 
        
const string& ExeName, bool Recur = false);

    
/*
     * @brief Create a new directory.
     * 
     * @param Dir  New directory path. Example:/home/bujiwu/test
     * 
     * @return  true, if success
     *          false, if failed
     
*/
    
static bool CreateDirectory(const string & Dir);

    
/*
     * @brief Judge whether this file or diretory exists.
     * 
     * @param Path
     * 
     * @return  true, if exists
     *          false, if not exists
     
*/
    
static bool Exists(const string& Path);

    
/*
     * @brief Delete this file or directory
     * 
     * @param Path
     
*/
    
static void Delete(const string& Path);

    
/*
     * @brief Move file or directory from FromPath to ToPath.
     * 
     * @param FromPath
     * @param ToPath
     
*/
    
static void Move(const string& FromPath, const string& ToPath);

    
/*
     * @brief Copy file or directory from FromPath to ToPath.
     * 
     * @param FromPath
     * @param ToPath
     
*/
    
static void Copy(const string& FromPath, const string& ToPath);

    
/*
     * @brief Get file size
     * 
     * @param FilePath
     * 
     * @return 
     
*/
    
static unsigned long GetFileSize(const string& FilePath);
};

#endif

嫻嬭瘯鐢ㄤ緥錛?br>
#include "../FileSystem/FileSystem.h"
#include 
<algorithm>
#include 
<iterator>
#include 
<string>

using namespace std;

int main(int argc, char* argv[])
{
    vector
<string> MyVec;

    
string Path = "/home/bujiwu/EncapDirectory";
    
    CFileSystem::Copy(
"/home/bujiwu/epoll", Path);

    CFileSystem::GetFiles(MyVec, Path, 
"*.*"true);

    copy(MyVec.begin(), MyVec.end(), ostream_iterator
<string>(cout , "\n") );

    
return 0;
}

http://www.shnenglu.com/Files/bujiwu/FileSystem.rar



bujiwu 2009-11-23 13:44 鍙戣〃璇勮
]]>
鍦↙inux涓嶹inodws涓嬬紪璇慴oosthttp://www.shnenglu.com/bujiwu/archive/2009/11/23/101689.htmlbujiwubujiwuMon, 23 Nov 2009 05:31:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/23/101689.htmlhttp://www.shnenglu.com/bujiwu/comments/101689.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/23/101689.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/101689.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/101689.htmldate_time
filesystem
function_types
graph
iostreams
math
mpi
program_options
python
regex
serialization
signals
system
test
thread
wave


Windows:
1銆佸紑濮嬭彍鍗?-Microsoft Visual Studio 2008--Visual Studio Tools---Open Visual Studio 2008 Command Prompt 鎵撳紑鍛戒護(hù)琛岀獥鍙?br>3銆佸埄鐢╟d鍛戒護(hù)榪涘叆鍒幫細(xì)boost->toos->jam->src鐩綍
4銆佺紪璇戯紝vc 2008杈撳叆鍛戒護(hù)錛歜uild vc9
5銆佹妸鐢熸垚鐨刡jam.exe(bin.ntx86鐩綍涓?鎷瘋礉鍒癇oost鏍圭洰褰曚笅錛岃緭鍏ュ懡浠わ細(xì)
6銆乥jam --with-regex

Linux:
 $cd path/to/boost_1_40_0
 $ ./bootstrap.sh
 浜х敓bjam鏂囦歡
 
 $ ./bjam install  瀹夎鎵鏈?br> $./bjam --with-regex  瀹夎鐗瑰畾鐨勫簱
 $./bjam --with-filesystem

 #./bjam --with-filesystem "-sTOOLS=gcc" "--includedir=/usr/include" "--libdir=/usr/lib/boost" install



bujiwu 2009-11-23 13:31 鍙戣〃璇勮
]]>
semaphore淇″彿瀛︿範(fàn)絎旇http://www.shnenglu.com/bujiwu/archive/2009/11/17/101190.htmlbujiwubujiwuTue, 17 Nov 2009 05:28:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/17/101190.htmlhttp://www.shnenglu.com/bujiwu/comments/101190.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/17/101190.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/101190.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/101190.htmlsem_init()
sem_destroy()
sem_post()
sem_wait()

//g++ -o semaphore semaphore.cpp  -lpthread
#include <semaphore.h>
#include 
<errno.h>
#include 
<unistd.h>
#include 
<pthread.h>
#include 
<stdlib.h>
#include 
<stdio.h>
#include 
<string.h>
#include 
"ThreadMutex.h"

#define MAXSIZE 10

sem_t g_sem_max;
sem_t g_sem_zero;

CThreadMutex g_mutex;

int g_count = 0;

int sem_wait_i(sem_t* psem)
{
    
int rv = 0;
   
    
while ( 0 != ( rv = sem_wait(psem) ) )
    {
        
if ( errno == EINTR )
        {
            
continue;
        }
        
else
        {
            printf(
"sem_wait %s\n", strerror(errno) );
            
break;
        }
    }

    
return rv;
}

void* producer_thread(void* Parameter)
{
    
whiletrue )
    {
        sleep(
2);

        
if( sem_wait_i(&g_sem_max) != 0 )
        {
            
break;
        }

        g_mutex.Lock();

        g_count
++;

        printf(
"Producer=%d\n", g_count);

        sem_post(
&g_sem_zero);

        g_mutex.UnLock();
    }

    
return NULL;
}

void* consumer_thread(void* Parameter)
{
    
whiletrue )
    {
        sleep(
3);

        
if( sem_wait_i(&g_sem_zero) != 0 )
        {
            
break;
        }

        g_mutex.Lock();

        g_count
--;

        printf(
"Consumer=%d\n", g_count);

        sem_post(
&g_sem_max);

        g_mutex.UnLock();
    }

    
return NULL;
}

int main(int argc, char* argv[])
{
    
if ( sem_init(&g_sem_zero, 00!= 0 )
    {
        printf(
"sem_init %s\n", strerror(errno) );

        
return -1;
    }

    
if ( sem_init(&g_sem_max, 0, MAXSIZE) != 0 )
    {
        printf(
"sem_init %s\n", strerror(errno) );

        
return -1;
    }

    pthread_t pro_thread;
    pthread_t sum_thread;

    
if ( pthread_create( &sum_thread, NULL, consumer_thread, NULL) != 0 )
    {
        printf(
"pthread_create%s\n", strerror(errno) );

        
return -1;
    }

    
if ( pthread_create( &pro_thread, NULL, producer_thread, NULL) != 0 )
    {
        printf(
"pthread_create%s\n", strerror(errno) );

        
return -1;
    }
    
    
if ( pthread_join(pro_thread, NULL) != 0 )
    {
        printf(
"pthread_join %s\n", strerror(errno) );

        
return -1;
    }

    
if ( pthread_join(sum_thread, NULL) != 0 )
    {
        printf(
"pthread_join %s\n", strerror(errno) );

        
return -1;
    }

    sem_destroy(
&g_sem_zero);
    sem_destroy(
&g_sem_max);

    
return 0;
}
http://www.shnenglu.com/Files/bujiwu/semaphore.rar



bujiwu 2009-11-17 13:28 鍙戣〃璇勮
]]>
setitimer鍑芥暟浣跨敤絎旇http://www.shnenglu.com/bujiwu/archive/2009/11/16/101061.htmlbujiwubujiwuMon, 16 Nov 2009 05:50:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/16/101061.htmlhttp://www.shnenglu.com/bujiwu/comments/101061.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/16/101061.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/101061.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/101061.html鍑芥暟鍘熷瀷 int setitimer(int which, const struct itimerval *value,
                     struct itimerval *ovalue);

DESCRIPTION
       The  system  provides each process with three interval timers, each decrementing in a distinct time domain.  When any timer expires, a
       signal is sent to the process, and the timer (potentially) restarts.

       ITIMER_REAL    decrements in real time, and delivers SIGALRM upon expiration.

       ITIMER_VIRTUAL decrements only when the process is executing, and delivers SIGVTALRM upon expiration.

       ITIMER_PROF    decrements both when the process executes and when the system is executing on behalf  of  the  process.   Coupled  with
                      ITIMER_VIRTUAL, this timer is usually used to profile the time spent by the application in user and kernel space.  SIG-
                      PROF is delivered upon expiration.

       Timer values are defined by the following structures:

            struct itimerval {
                struct timeval it_interval; /* next value */
                struct timeval it_value;    /* current value */
            };
            struct timeval {
                long tv_sec;                /* seconds */
                long tv_usec;               /* microseconds */
            };

#include <stdio.h>
#include 
<unistd.h>
#include 
<signal.h>
#include 
<string.h>
#include 
<sys/time.h>
#include 
<errno.h>

void PrintMsg(int Num)
{
    printf(
"%s\n""Hello World");

    
return;
}

int main(int argc, char* argv[])
{
    signal(SIGALRM, PrintMsg);

    
struct itimerval tick;
    tick.it_value.tv_sec 
= 10;  //鍗佺閽熷悗灝嗗惎鍔ㄥ畾鏃跺櫒
    tick.it_value.tv_usec = 0;
    tick.it_interval.tv_sec  
=1//瀹氭椂鍣ㄥ惎鍔ㄥ悗錛屾瘡闅?縐掑皢鎵ц鐩稿簲鐨勫嚱鏁?/span>
    tick.it_interval.tv_usec = 0;

    
//setitimer灝嗚Е鍙慡IGALRM淇″彿
    int ret = setitimer(ITIMER_REAL, &tick, NULL);

    
if ( ret != 0)
    {
        printf(
"Set timer error. %s \n", strerror(errno) );

        
return -1;
    }

    printf(
"Wait!\n");

    getchar();

    
return 0;
}



bujiwu 2009-11-16 13:50 鍙戣〃璇勮
]]>
pthread_mutex_t灝佽http://www.shnenglu.com/bujiwu/archive/2009/11/08/pthread_mutex.htmlbujiwubujiwuSun, 08 Nov 2009 12:57:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/08/pthread_mutex.htmlhttp://www.shnenglu.com/bujiwu/comments/100413.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/08/pthread_mutex.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/100413.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/100413.html
//Mutex.cpp
#include 
<pthread.h>
#include 
<iostream>
using namespace std;

class ThreadMutex
{
public:
    ThreadMutex()
    {
        pthread_mutex_init(
&mtx, NULL);
    }
    
    
~ThreadMutex()
    {
        pthread_mutex_destroy( 
&mtx );
    }
    
    inline 
void Lock()
    {
        pthread_mutex_lock( 
&mtx );
    }
    
    inline 
void UnLock()
    {
        pthread_mutex_unlock( 
&mtx );
    }
    
private:
    pthread_mutex_t mtx;
};                                                            

//浠ヤ笅涓烘祴璇曠敤渚?br>ThreadMutex g_Mutex;

void *PrintMsg(void *lpPara)
{
    
char *msg = (char *)lpPara;

    g_Mutex.Lock();

    
for(int i=0; i< 5; i++ )
    {
        cout 
<< msg << endl;
        sleep( 
1 );
    }

    g_Mutex.UnLock();

    
return NULL;
}

int main()
{
    pthread_t t1,t2;

    
//鍒涘緩涓や釜宸ヤ綔綰跨▼錛岀1涓嚎紼嬫墦鍗?0涓?錛岀2涓嚎紼嬫墦鍗?0涓?銆?/span>
    pthread_create( &t1, NULL, &PrintMsg, (void *)"First print thread" );       
    pthread_create( 
&t2, NULL, &PrintMsg, (void *)"Second print thread" );        

    
//絳夊緟綰跨▼緇撴潫                                             
    pthread_join( t1, NULL);                               
    pthread_join( t2, NULL);                               

    
return 0;                                             
}    

閫氳繃g++ -o Mutex Mutex.cpp -lpthread緙栬瘧銆?br>

bujiwu 2009-11-08 20:57 鍙戣〃璇勮
]]>
榪涚▼闂撮氳--System V 鍏變韓鍐呭瓨http://www.shnenglu.com/bujiwu/archive/2009/11/08/100390.htmlbujiwubujiwuSun, 08 Nov 2009 01:39:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/08/100390.htmlhttp://www.shnenglu.com/bujiwu/comments/100390.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/08/100390.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/100390.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/100390.html
#include <sys/ipc.h>
#include 
<sys/shm.h>
#include 
<unistd.h>
#include 
<errno.h>
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<errno.h>
#include 
<sys/types.h>

using namespace std;


int main(int argc, char* argv[])
{
    key_t key 
= ftok("/etc/passwd"'a');
    
if-1 == key )
    {
        fprintf(stderr, 
"Creat Key Error:%s\n", strerror(errno));
        
return -1;
    }
    
    
/*
     if your IPC are used by processes related bya fork() 
    (parent-children-grandchildren) use IPC_PRIVATE as the key
    
*/
    
int shm_id=shmget( key, 1024, IPC_CREAT |0660);

    
if( shm_id == -1 )
    {
        
if ( shmctl(shm_id, IPC_RMID, NULL) == -1 )
        {
            fprintf(stderr, 
"shmctl remove shmid error:%s\n", strerror(errno ));
            
return -1;
        }

        shm_id
=shmget( key, 1024, IPC_CREAT |0660);
        
if( shm_id == -1 )
        {
            fprintf(stderr, 
"shmget create error:%s\n", strerror(errno) );
            
return -1;
        }
    }

    
char* pMap = (char *)shmat(shm_id, NULL, 0);

    
if( (int)pMap == -1)
    {
        fprintf(stderr, 
"shmat create error:%s\n", strerror(errno) );
        shmctl(shm_id, IPC_RMID, NULL);
        
return -1;
    }

    strcpy( pMap, 
"Bujiwu Swallow");

    getchar();

    shmdt(pMap);
    shmctl(shm_id, IPC_RMID, NULL);

    
return 0;
}

#include <sys/ipc.h>
#include 
<sys/shm.h>
#include 
<unistd.h>
#include 
<errno.h>
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<errno.h>
#include 
<sys/types.h>

using namespace std;

int main(int argc, char* argv[])
{
    key_t key 
= ftok("/etc/passwd"'a');
    
if-1 == key )
    {
        fprintf(stderr, 
"Creat Key Error:%s\n", strerror(errno));
        
return -1;
    }
    
    
/*
     if your IPC are used by processes related bya fork() 
    (parent-children-grandchildren) use IPC_PRIVATE as the key
    
*/
    
int shm_id=shmget( key, 1024, IPC_CREAT|0660);
    
    
if( shm_id == -1 )
    {
        
if ( shmctl(shm_id, IPC_RMID, NULL) == -1 )
        {
            fprintf(stderr, 
"shmctl remove shmid error:%s\n", strerror(errno ));
            
return -1;
        }

        shm_id
=shmget( key, 1024, IPC_CREAT |0660);
        
if( shm_id == -1 )
        {
            fprintf(stderr, 
"shmget create error:%s\n", strerror(errno) );
            
return -1;
        }
    }
    
char* pMap = (char *)shmat(shm_id, NULL, 0);

    
if( (int)pMap == -1)
    {
        fprintf(stderr, 
"shmat create error:%s\n", strerror(errno) );
        shmctl(shm_id, IPC_RMID, NULL);
        
return -1;
    }

    printf(
"Shared  memory::%s\n", pMap);

    shmdt(pMap);
    shmctl(shm_id, IPC_RMID, NULL);

    
return 0;
}

http://www.shnenglu.com/Files/bujiwu/ShareMemory.rar


bujiwu 2009-11-08 09:39 鍙戣〃璇勮
]]>
久久久久亚洲精品天堂| 久久夜色精品国产亚洲| 伊人久久大香线蕉av不变影院| 亚洲色欲久久久综合网东京热| 亚洲人成伊人成综合网久久久| 久久久噜噜噜久久中文福利| 国产精品免费看久久久| 国产香蕉久久精品综合网| 国产A级毛片久久久精品毛片| 久久天天躁狠狠躁夜夜avapp| 国产精品福利一区二区久久| 久久国产精品视频| 99精品久久久久久久婷婷| 久久精品国产亚洲av影院| 久久精品免费一区二区三区| 无码人妻久久一区二区三区蜜桃| 亚洲中文字幕久久精品无码喷水| 99久久无码一区人妻a黑| 精品久久久久久久久久中文字幕| 久久亚洲国产精品成人AV秋霞| 国产午夜精品久久久久免费视| 99久久99久久精品国产片果冻| 亚洲美日韩Av中文字幕无码久久久妻妇 | 亚洲综合久久夜AV | av无码久久久久久不卡网站| 久久影视国产亚洲| 久久国产精品成人影院| 久久无码一区二区三区少妇 | 久久91精品久久91综合| 色婷婷综合久久久久中文字幕| 国产亚洲精品自在久久| 久久夜色精品国产亚洲| 精品国产婷婷久久久| 99久久婷婷国产综合亚洲| 日韩人妻无码一区二区三区久久99| 26uuu久久五月天| 久久久久亚洲AV无码麻豆| 中文字幕无码久久人妻| 狠狠色伊人久久精品综合网 | 超级97碰碰碰碰久久久久最新| 色综合久久88色综合天天|