日期:2014-05-16 浏览次数:20579 次
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> #include <signal.h> /* int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); */ void* thread_func(void*) { while(1) { pause(); } } void sigfunc(int) { write(1, "!", 1); sleep(10); } int main() { pthread_t tid; signal(SIGINT, sigfunc); if (pthread_create(&tid, NULL, thread_func, NULL) == -1) { perror("pthread_create"); exit(1); } while(1) { pause(); } return 0; }