Can't compile a program that calls tgkill

廉价感情. 提交于 2019-12-10 18:17:48

问题


I'm trying to write a program that uses tgkill to send a signal to a specific thread, but whenever I compile it with gcc I get an error about an undefined reference to 'tgkill'. I tried compiling with -lpthread but it didn't help. I've googled and googled and can't come up with any answers. How do I get it to compile??


回答1:


From the tgkill() manpage:

Glibc does not provide wrappers for these system calls; call them using syscall(2).




回答2:


You might want to use something like this instead.

tgid=getpid();  
tid=gettid();  
syscall(SYS_tgkill, tgid, tid, signalname));



回答3:


As noted in another answer, glibc does not provide wrappers for tkill() or tgkill().

Instead, you're supposed to use pthread_kill().



来源:https://stackoverflow.com/questions/5374960/cant-compile-a-program-that-calls-tgkill

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!