NDK-JNI-pthread_kill结束线程
2014-06-06 11:42
447 查看
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
pthread_t pid;
void handle_quit(int signo)
{
printf("in qq handle sig %d \n", signo);
pthread_exit(NULL);
}
void* test(void *arg)
{
signal(SIGQUIT,handle_quit );
for(int i=0;i<100;i++)
{
printf("in pthread test \n");
sleep(1);
}
}
int main(void)
{
printf("begin \n");
pthread_create(&pid, NULL , test, NULL);
sleep(3);
if(pthread_kill(pid, 0)!= ESRCH)
{
printf("thread %d exists!\n", pid);
pthread_kill(pid, SIGQUIT);
// pthread_exit(NULL);//this won't work
printf("after kill\n");
}
sleep(1);
printf("exit in main\n");
}
相关文章推荐
- NDK-JNI-pthread_kill结束线程
- linux中使用pthread_kill函数测试线程是否存活的例子
- linux中使用pthread_kill函数测试线程是否存活的例子
- pthread_kill-----向线程发送信号
- linux线程通信:sigwait和pthread_kill
- linux中使用pthread_kill函数测试线程是否存活
- Windows和Linux上分别怎样实现等待某个线程结束?---用WaitForSingleObject和pthread_join
- 线程正常终止pthread_exit,pthread_join,pthread_kill,pthread_cancel,sigwait,sigaddset
- linux中使用pthread_kill函数测试线程是否存活
- 在native线程利用JNI 反射自定义类--ndk开发参考2
- linux中使用pthread_kill函数测试线程是否存活
- linux线程通信:sigwait和pthread_kill
- pthread_cancel() 能结束哪些线程-linux
- linux中使用pthread_kill函数测试线程是否存活
- linux多线程之pthread_cancel结束线程
- linux中使用pthread_kill函数测试线程是否存活
- linux中使用pthread_kill函数测试线程是否存活
- LINUX中使用PTHREAD_KILL函数测试线程是否存活的例子
- 线程正常终止pthread_exit,pthread_join,pthread_kill,pthread_cancel,sigwait,sigaddset
- linux中使用pthread_kill函数测试线程是否存活