多線程編程之:Linux線程編程
接下來(lái)可以在線程運(yùn)行前后使用“free”命令查看內(nèi)存的使用情況。以下是運(yùn)行結(jié)果:
$ ./thread_attr
Create tread success
Waiting for thread to finish...
Thread is starting
Waiting for thread to finish...
Thread : job 0 delay = 3
Waiting for thread to finish...
Thread : job 1 delay = 2
Waiting for thread to finish...
Waiting for thread to finish...
Waiting for thread to finish...
Waiting for thread to finish...
Thread : job 2 delay = 9
Thread finished
/* 程序運(yùn)行之前 */
$ free
total used free shared buffers cached
Mem: 255556 191940 63616 10 5864 61360
-/+ buffers/cache: 124716 130840
Swap: 377488 18352 359136
/* 程序運(yùn)行之中 */
$ free
total used free shared buffers cached
Mem: 255556 191948 63608 10 5888 61336
-/+ buffers/cache: 124724 130832
Swap: 377488 18352 359136
/* 程序運(yùn)行之后 */
$ free
total used free shared buffers cached
Mem: 255556 191940 63616 10 5904 61320
-/+ buffers/cache: 124716 130840
Swap: 377488 18352 359136
可以看到,線程在運(yùn)行結(jié)束后就收回了系統(tǒng)資源,并釋放內(nèi)存。
linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)linux相關(guān)文章:linux教程
評(píng)論