zoukankan      html  css  js  c++  java
  • 一个进程监控程序

    linux下使用

    采用sh的模式,会导致开机alt+f2无法正常使用。故替换之#include <stdio.h>

    #include <unistd.h>
    #include 
    <errno.h>
    #include 
    <string.h>
    #include 
    <sys/types.h>
    #include 
    <sys/wait.h>
    #include 
    <stdlib.h>

    int main(int argc,char **argv)
    {
      
    int ret, i, status;
      
    char *child_argv[200= {"/usr/share/TSMIS/bin/TSMIS_JK"};
      pid_t pid;
      
    while(1)
      {
        pid 
    = fork();
        
    if (pid == -1)
        {
           fprintf(stderr, 
    "fork() error.errno:%d error:%s\n", errno, strerror(errno));
           
    break;
        }

        
    if (pid == 0)
        {
          ret 
    = execlp(child_argv[0],child_argv[0],(char*)0);
          
    if (ret < 0)
          {
             fprintf(stderr, 
    "execv ret:%d errno:%d error:%s\n", ret, errno, strerror(errno));
             
    continue;
          }
          exit(
    0);
        }
       
    if (pid > 0)
       {
          
    //pid = wait(&status);
          
    //
          waitpid(pid,&status,0);
          fprintf(stdout, 
    "wait return");
          sleep(
    5);
       }
     }
     
    return 0;

    } 

  • 相关阅读:
    DAO模式多表联查
    使用ADO.NET访问数据库
    连接查询和分组查询
    模糊查询和聚合函数
    poj 1220 NUMBER BASE CONVERSION
    poj 1964 City Game
    Odd number problem
    POJ 2983 M × N Puzzle
    L O V E
    【Mybatis】【3】处理大于号小于号及其他特殊字符
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/2080200.html
Copyright © 2011-2022 走看看