![]() |
#2
rjsp2022-09-10 13:12
|

#include "apue.h"
void *thread_fun(void *arg){
sleep(1);
printf("wo shi new thread\n");
return (void *)0;
}
int main(int argc, char **argv){
pthread_t tid;
int err;
int s;
void *rval;
err = pthread_create(&tid, NULL, thread_fun, NULL);
if (err) {
printf("pthread_create error\n");
return 0;
}
//sleep(1);
s = pthread_kill(tid,SIGQUIT); //向新线程发送信号
if (s == ESRCH){ //检测线程是否存在
printf("new thread is not found\n");
}
printf("new thread exit code is %d\n",pthread_join(tid,&rval));
/// system("pause");
return 0;
}
void *thread_fun(void *arg){
sleep(1);
printf("wo shi new thread\n");
return (void *)0;
}
int main(int argc, char **argv){
pthread_t tid;
int err;
int s;
void *rval;
err = pthread_create(&tid, NULL, thread_fun, NULL);
if (err) {
printf("pthread_create error\n");
return 0;
}
//sleep(1);
s = pthread_kill(tid,SIGQUIT); //向新线程发送信号
if (s == ESRCH){ //检测线程是否存在
printf("new thread is not found\n");
}
printf("new thread exit code is %d\n",pthread_join(tid,&rval));
/// system("pause");
return 0;
}

#include "apue.h"中包含的头文件如下
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>
#include<sys/types.h>
#include <signal.h>
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>
#include<sys/types.h>
#include <signal.h>
signal.h头文件中
#ifdef _POSIX
以下的显示为灰色
#define SIGHUP 1 /* hangup */
#define SIGQUIT 3 /* quit */
#define SIGTRAP 5 /* trace trap (not reset when caught) */
#define SIGIOT 6 /* IOT instruction */
#define SIGEMT 7 /* EMT instruction */
#define SIGKILL 9 /* kill (cannot be caught or ignored) */
#define SIGBUS 10 /* bus error */
#define SIGSYS 12 /* bad argument to system call */
#define SIGPIPE 13 /* write on a pipe with no one to read it */