#include <iostream>
#include <sys/prctl.h>
void th1(void)
{
prctl(PR_SET_NAME, __FUNCTION__);
while(1){
std::this_thread::sleep_for(std::chrono::milliseconds(100);
}
int main(int argc, char *argv[])
{
printf("pid: %d\n", getpid());
prctl(PR_SET_NAME, "LY");//修改主线程的名称,其实也就修改了进程名。
std::thread Thread1(th1);
Thread1.detach();
while(1){
//sleep(1);
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
select(0, NULL, NULL, NULL, &tv);
}
}
top -Hp `pgrep LY` //打印进程的线程(cpu,内存)使用情况