#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <sys/syscall.h>
pthread_t tid[10];
void * thread_handler(void *arg)
{
printf("thread num =%d lwpid=%u ...tid:%u,parentid:%u\n",(int)arg, syscall(SYS_gettid), (unsigned)pthread_self(),
(unsigned)getpid());
while(1){
if((int)arg ==2)
{
char *p =(char*)malloc(sizeof(char) * 120);// new char[100000];
usleep(100);
}
else
sleep(1);
}
return NULL;
}
int main(void)
{
int i, ret;
pid_t pid;
printf("main tid:%u,pid:%u\n", (unsigned)pthread_self(),
(unsigned)getpid());
for(i = 0; i < 10; i++){
if((ret = pthread_create(&tid[i], NULL, thread_handler,
(void *)i)) != 0){
fprintf(stderr, "pthread_create:%s\n",
strerror(ret));
exit(1);
}
}
sleep(3);
pid = fork();
if(pid == 0){
printf("son tid:%u,pid:%u\n", (unsigned)pthread_self(),
(unsigned)getpid());
while(1);
sleep(1);
}
while(1)
sleep(2);
exit(0);
}
ps a 找到test进程的PID 然后top -H -p [PID] 可以查看这个进程 所有线程的CPU使用率,,,,,但是所有线程的内存使用是一样的,,,,这个无法查看线程的内存占用。