#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/prctl.h>
static void *test_thread(void *arg)
{
int val = *((int *)arg);
struct sched_param param;
sched_getparam(0, ¶m);
param.__sched_priority = 20;
sched_setscheduler(0, SCHED_FIFO, ¶m);
prctl(PR_SET_NAME, __func__, 0, 0, 0);
while (1)
{
usleep(10);
printf("%s is running, val:%d...\n", __func__, val);
}
return (void *)0;
}
int main(void)
{
int ret;
pthread_t th_id;
int arg = 10;
ret = pthread_create(&th_id, NULL, (void*)test_thread, (void *)&arg);
if (0 != ret)
printf("creat thread failed!\n");
ret = pthread_detach(th_id);
if (0 != ret)
printf("detach thread failed!\n");
while(1)
sleep(1);
return 0;
}
//top -H -d1 看线程名字