Linux多线程实例 定时重启httpd和mysqld
#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