#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

Linux多线程实例 定时重启httpd和mysqld的更多相关文章

  1. Linux多线程实例练习 - pthread_cancel()

    Linux多线程实例练习 - pthread_cancel 1.代码 xx_pthread_cancel.c #include <pthread.h> #include <stdio ...

  2. Linux多线程实例练习 - pthread_exit() 与 pthread_join()

    Linux多线程实例练习 - pthread_exit 与 pthread_join pthread_exit():终止当前线程 void pthread_exit(void* retval); pt ...

  3. Linux多线程实例练习 - pthread_create()

    Linux多线程实例练习 pthread_create():创建一个线程 int pthread_create(pthread_t *tidp, const pthread_attr_t *attr, ...

  4. Linux多线程实例解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread.编写Linux下的多线程程序,需要使用头文件pthread.h,连接时需要使用库libpthread.a.顺便说一下,Linux ...

  5. Linux CentOS设置定时重启:crontab

    上一篇介绍了 开机自启动chkconfig命令  https://www.cnblogs.com/prefectjava/p/9399470.html 本篇介绍 crontab 设置定时任务,并且把 ...

  6. linux定时重启tomcat服务的脚本学习

    要求:在linux中定时重启一个tomcat服务 一:shell脚本即Shell Script [1],Shell脚本与Windows/Dos下的批处理相似,也就是用各类命令预先放入到一个文件中,方便 ...

  7. 【树莓派】crontab设置Linux设备定时重启

    简介:设置Linux设备定时重启或者关机 问题:有台设备每天总需要使用的人手动重启一下才可以正常工作,但是检查了日志,看起来服务一切都正常.时间和正确时间相差4mins. 解决办法: 1.增加定时任务 ...

  8. linux定时重启节约内存

    linux服务器上运行的一些程序,比较消耗内存,需要定时重启,进行内存定期释放 0 2 * * *  sudo /sbin/reboot && echo $(date) '重启成功' ...

  9. Linux 定时重启 Tomcat、重启Keepalived

    1.在 tomcat 目录新建一个.sh 文件: vi restartTomcat.sh 2.输入内容: #!/bin/bash# author: Linnuo # date: -- # Filena ...

随机推荐

  1. ELK踩过的各种坑 6.4版本

    一.elasticsearch 1.服务正常启动,但不能正常访问 [root@linux-node1 elasticsearch]# systemctl start elasticsearch [ro ...

  2. Ajax跨域问题---jsonp

    跨域:跨域名  一个域名下的文件去请求了和他不一样的域名下资源文件,那么就会产生跨域请求 解决跨域问题办法: 1.将要访问的外部资源存到本域名下的一个php文件 2.用flash方式 3.JSONP: ...

  3. 我的Python分析成长之路3

    一 集合                                                                                                 ...

  4. Java集合之PriorityQueue

    PriorityQueue 定义 C++:priority_queue Java:PriorityQueue 创建与其基本操作 创建: PriorityQueue<Integer>=new ...

  5. Java实现——Dom4j读写XML文件

    1. dom4j概述 解析DOM4J是一个开源XML解析包,采用了Java集合框架并完全支持DOM,SAX和JAXP. 最大的特色是使用了大量的接口,主要接口都在org.dom4j里定义. 2. do ...

  6. pytorch遇到的问题:RuntimeError: randperm is only implemented for CPU

    由此,我们找到sample.py,第51行如下图修改

  7. [uiautomator篇] bluetooth---接口来做

    package com.softwinner.performance.frameratetest; import android.Manifest; import android.bluetooth. ...

  8. php 注册与登录

    <body background="timg.jpg"><div class="dak"> <div class="zu ...

  9. nginx 的日志切割

    nginx的日志切割脚本 说明:在nginx的配置文件中nginx.conf并没有定义access_log的位置, 在/usr/local/nginx/conf/vhost/下的配置文件中定义了acc ...

  10. [luoguP3953] 逛公园(DP + spfa)

    传送门 看到求方案数,应该很容易想到dp f[u][i]表示到点u,且比到u的最短距离多i的方案数 那么需要先预处理dis数组,spfa或者堆优化的dijk 因为考虑到dp的顺序,f[u][i]转移到 ...