gcc 编译时出现permission denied 求解。
#include <stdio.h>#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <string.h>
void sig_handlerl1(int arg)
{
printf("this is sig_handler 1\n");
}
void sig_handlerl2(int arg)
{
printf("this is sig_handler 2\n");
}
void *thread1(void *arg)
{
printf("this is thread 1\n");
struct sigaction act;
sigset_t sa_mask;
memset(&act,0,sizeof(act));
sigaddset(&sa_mask,SIGQUIT);
act.sa_handler=sig_handlerl1;
sigaction(SIGQUIT,&act,NULL);
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask,SIGQUIT);
pthread(SIG_BLOCK,&mask,NULL);
sleep(6);
}
void *thread2(void *arg)
{
printf("this is thread 2\n");
struct sigaction act;
sigset_t sa_mask;
memset(&act,0,sizeof(act));
sigaddset(&sa_mask,SIGQUIT);
act.sa_handler=sig_handlerl2;
sigaction(SIGQUIT,&act,NULL);
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask,SIGQUIT);
pthread(SIG_BLOCK,&mask,NULL);
sleep(3);
}
int main()
{
pthread_t pid1,pid2;
pthread_create(&pid1,NULL,thread1,NULL);
pthread_create(&pid2,NULL,thread2,NULL);
sleep(1);
pthread_kill(pid1,SIGQUIT);
pthread_kill(pid2,SIGQUIT);
pthread_join(pid1,NULL);
pthread_join(pid2,NULL);
return 0;
}
文件名sigac.c
编译命令如下
gcc -pthread -c sigac.c -o main
执行 ./main
出现 ./main permission denied
求各位指教。。