1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <stdio.h> #include <pthread.h> void *start_routine(void *arg) { while(1) { system("service httpd restart"); system("service mysqld restart"); sleep(60*60*6); } int retvalue = 0; pthread_exit((void*)&retvalue); } int main() { pthread_t pt; int ret; ret = pthread_create(&pt,NULL,(void*)start_routine,0); if(ret != 0) { printf("create thread error"); return 0; } int *ret_join = NULL; pthread_join(pt,(void*)&ret_join); printf("retvalue: %d\n",*ret_join); return 0; } |
gcc test.c -o test -lpthread