Library Include with Tkill

I tried use tkill ,to kill some thread with c code .

What are the library I need to include to use this function?

Running on linux ubuntu

int main(int argc , char* argv[])
{
   tkill(123,9);

}
3

1 Answer

You neeed syscall(SYS_tkill, ThePid, TheSignal).

Example:

#include <unistd.h>
#include <sys/syscall.h>
#include <signal.h>
int main()
{
    //kills self:
    pid_t tid = syscall(SYS_gettid);
    syscall(SYS_tkill,tid,SIGTERM); 
    return 0;
}

Glibc has had a policy of not including wrappers for non-POSIX syscalls. They may be changing it in current/future versions but using the generic syscall syscall-making function should always work on Linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest