İşletim Sistemleri (Bahar-2016) Hafta-11/1
#include<iostream> #include<signal.h> #include<pthread.h> #include<sys/syscall.h> #include <unistd.h> using namespace std; void yakala(int sinyaltipi) { cout<<"Sinyali yakalayan iplik:"<<syscall(SYS_gettid)<<"--"<<endl; } void * iplik_islem(void *arg) { cout<<"Kimligim:"<<syscall(SYS_gettid)<<"--"<<endl; } int main() { pthread_t iplik[2]; int i; cout<<"Program:: sinyal yakala"<<endl; signal(SIGINT,&yakala); cout<<"Program:: create"<<endl; for(i=0;i<2;i++) pthread_create(&iplik[i],NULL,iplik_islem,NULL); cout<<"Program:: SIGINT iplik[0]"<<endl; pthread_kill(iplik[0],SIGINT); cout<<"Program:: join"<<endl; for(i=0;i<2;i++) pthread_join(iplik[i],NULL); } .
Terminalde derlemek için: g++ ornek1.cpp -o ornek1 -pthread