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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.