|
线程函数里什么都不干,pthread_join后线程占用的空间还是不释放。各位老大指教
:tmp$ gcc a.c -lpthread
:tmp$ ./a.out &
main process
[1] 3817
开始没有进入进程时,只有2M内存
:tmp$ ps aux|grep -i a.out
b17931 3817 0.0 0.0 1728 392 pts/2 S 11:37 0:00 ./a.out
b17931 3819 0.0 0.0 3068 788 pts/2 R+ 11:37 0:00 grep -i a.out
:tmp$ thread fn1
线程执行完后,pthread_join了,应该释放内存,但是居然一直占用10M
:tmp$ ps aux|grep -i a.out
b17931 3817 0.0 0.0 10056 460 pts/2 S 11:37 0:00 ./a.out
b17931 3822 0.0 0.0 3068 788 pts/2 R+ 11:37 0:00 grep -i a.out
:tmp$
程序代码:- #include <stdio.h>
- #include <pthread.h>
- void* fn1(void* arg)
- {
- printf("thread fn1\n");
- return NULL;
- }
- int main()
- {
- pthread_t tid;
- printf("main process\n");
- sleep(20);
- pthread_create(&tid, NULL, fn1, NULL);
- pthread_join(tid, NULL);
- sleep(500);
- return 0;
- }
复制代码 |
|