bool
ServerProcess::isAlreadyRunning()
{
#ifndef __linux__
WarningLog(<<"can't check if process already running on this platform (not implemented yet)");
return false;
#else
if(mPidFile.size() == )
{
// if no PID file specified, we do not make any check
return false;
} pid_t running_pid;
std::ifstream _pid(mPidFile.c_str(), std::ios_base::in);
if(!_pid.good())
{
// if the file doesn't exist or can't be opened, just ignore
return false;
}
_pid >> running_pid;
_pid.close(); StackLog(<< mPidFile << " contains PID " << running_pid); Data ourProc = Data("/proc/self/exe");
Data otherProc = Data("/proc/") + Data(running_pid) + Data("/exe");
char our_exe[], other_exe[];
int buf_size; buf_size = readlink(ourProc.c_str(), our_exe, );
if(buf_size < || buf_size == )
{
// if readlink fails, just ignore
return false;
}
our_exe[buf_size] = ; buf_size = readlink(otherProc.c_str(), other_exe, );
if(buf_size < || buf_size == )
{
// if readlink fails, just ignore
return false;
}
other_exe[buf_size] = ; if(strcmp(our_exe, other_exe) == )
{
ErrLog(<<"already running PID: " << running_pid);
return true;
}
return false;
#endif
}

最新文章

  1. ajax的post方式和get方式比较,以及需要注意的地方
  2. Util应用程序框架公共操作类(五):异常公共操作类
  3. ASP.NET WEB API必知必会:特性路由
  4. IOS 网络浅析-(八 NSURLSession简介)
  5. 编写爬虫程序的神器 - Groovy + Jsoup + Sublime
  6. button swift
  7. iOSbase64
  8. JS中的substring和substr函数的区别
  9. yii2源码学习笔记(十三)
  10. mysql 增量导入到elasticsearch
  11. Mysql日期函数,时间函数使用的总结
  12. de4dot命令 v2.0.3.3405
  13. ini文件必须要全路径名啊
  14. 第三章 go语言 程序的流程控制
  15. Short But Scary 解题报告
  16. Redis 中可以存储的五种基本类型
  17. C# Note26: [MethodImpl(MethodImplOptions.Synchronized)]与lock机制
  18. RISC与CISCCPU构架
  19. 「雅礼集训 2017 Day1」 解题报告
  20. 向ACCESS数据库中的表导入EXCEL表,在 System.Data.OleDb.OleDbException 中第一次偶然出现的“System.Data.dll”类型的异常

热门文章

  1. Java toString()方法
  2. Android屏幕适配方案——基于最小宽度(Smallest-width)限定符
  3. oracle的同义词总结
  4. php Reflection
  5. WEB服务重要基础
  6. 接触C# 反射
  7. MVC项目不同域之间的UrlRouting
  8. MaperReduce实验
  9. Delphi三层开发小技巧:TClientDataSet的Delta妙用
  10. MD5类库(hex_md5)