我研究如何获得线程ID当函数timer_create()被调用。 我观察到,每次的timer_create()被调用时,一个新的线程(主进程的子线程)创建。 我用ps证实了这一-el | grep的
我需要通过PS-EL我的程序,其采用timer_create内显示相同的TID(子线程ID)。 从下面的代码:如何让我的节目里面的TID 18018?
我已经研究了所有的职位,每个人提到了一个新的线程上调用通知功能,而不是调用timer_create()创建的。
我感谢你的帮助非常感谢!
码:
SLGTRACER_DEFINE(testMain, "testMain");
timer_t audit_timer1;
void timeoutHandler(sigval_t info)
{
slgInfo(testMain, "timeoutHandler invoked");
slgInfo(testMain, "gettid() = %lu TESTMAIN", syscall(SYS_gettid));
slgInfo(testMain, "getpid() = %d TESTMAIN", getpid());
}
int main(void)
{
slgInfo(testMain, "testMain Invoked");
struct sigevent evp1;
evp1.sigev_notify = SIGEV_THREAD;
evp1.sigev_value.sival_ptr = &audit_timer1;
evp1.sigev_notify_function = timeoutHandler;
evp1.sigev_notify_attributes = NULL;
const int ERROR_BUFFER_SIZE = 50;
slgInfo(testMain, "Before FIRST timer_create");
sleep(30);
// Create timer thread
if (timer_create(CLOCK_REALTIME, &evp1, &audit_timer1) != 0)
{
// Character buffer for storing error message.
char errBuff[ERROR_BUFFER_SIZE];
memset(errBuff, 0, ERROR_BUFFER_SIZE);
slgError(testMain,
"timer_start create failed. Error = %s",
strerror_r(errno, errBuff, ERROR_BUFFER_SIZE));
timer_delete(audit_timer1);
bzero(&audit_timer1, sizeof(audit_timer1));
}
slgInfo(testMain, "After FIRST timer_create");
sleep(30);
return 0;
}
bash-3.1# ps -eL|grep testM
16651 16651 pts/0 00:00:00 testMain
16651 18018 pts/0 00:00:00 testMain
child thread with ID created by timer_create() = 18018