Riorita Riorita - 26 days ago 16
C Question

phtread_kill() Segmentation fault (core dumped)

I have a list of java threads

top -H -p [java ppid number]
and want to kill certain with pthread_kill() by C call

#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <linux/unistd.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>

int main(void)
{
pthread_kill(23242,SIGKILL);
return 0;
}


Compiling like this

sudo gcc ckill.c -o comp -pthread


returns


Segmentation fault (core dumped)


What's wrong?

usr usr
Answer

pthread_kill() can send a signal to a thread within the same process. And for that reason, it takes a pthread_t as an argument, not a PID. So you can't send signals to some java process as you are doing.

If you want to send a signal to any process on the system, have a look at kill().

Comments