zoukankan      html  css  js  c++  java
  • pid文件

    the pid files contains the process id (a number) of a given program. For example, Apache HTTPD may write it's main process number to a pid file - which is a regular text file, nothing more than that -, and later use the information there contained to stop itself. You can also use that information (just do a cat filename.pid) to kill the process yourself, using kill <the number in the .pid file>

    /*
     ============================================================================
     Name        : testc.c
     Author      : 
     Version     :
     Copyright   : Your copyright notice
     Description : pid文件的使用,一个终端运行该程序,另一个终端输入 kill -9 `cat testc.pid`
                   即可杀死该程序。注意路径和符号``.
     ============================================================================
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <unistd.h>
    
    int write_pid(void);
    
    int main(void) {
    	printf("Hello World!\n");
    
    	if(write_pid() < 0)
    	{
    		printf("cannot write pid file!");
    		return -1;
    	}
    
    	while (1)
    	{
    
    	}
    
    	return 0;
    }
    
    int write_pid(void)
    {
    	FILE *f;
    
    	if(!(f = fopen("testc.pid","w")))
    	{
    		return -1;
    	}
    
    	fprintf(f,"%d",(int)getpid());
    	fclose(f);
    
    	return 0;
    }
  • 相关阅读:
    性能测试系列七 工具选择
    Selenium Web自动化面试题总结(下篇)
    性能测试系列六 评估压测量
    hexo 安装
    光纤收发器组网方式
    频谱仪
    交换机网管telent
    区块链共识机制
    SDH、MSTP、OTN和PTN
    ACL知识
  • 原文地址:https://www.cnblogs.com/helloweworld/p/2729062.html
Copyright © 2011-2022 走看看