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
}

Linux 判断进程是否已经运行的程序的更多相关文章

  1. linux根据进程号PID查找启动程序的全路径

    linux根据进程号PID查找启动程序的全路径 2014-01-25 11:09 18629人阅读 评论(0) 收藏 举报  分类: Linux系统管理(29)  版权声明:本文为博主原创文章,未经博 ...

  2. Linux查看进程启动时间和运行多长时间

    Linux 查看进程启动时间和运行多长时间 启动时间 ps -eo lstart 运行多长时间 ps -eo etime -bash-4.1$ ps -eo pid,lstart,etime | gr ...

  3. 在linux下安装eclipse以及运行c++程序的安装步骤

    1.       下载jre,eclipse,cdt 其中jre是java运行环境,eclipse需要先装jre,才可能运行,cdt是在eclipse中运行c\c++程序的插件. 下载jre 网址是: ...

  4. 如何在linux下安装jdk并运行java程序

    一.进入root 大家可以看到我这里用的是CentOS 6.5 系统 二.测试网络与YUM是否可用 1.测试网络 ping www.baidu.com,如下图就是通了 参考: 一.JDK安装1.lin ...

  5. Linux 判断进程是否运行

    问题 linux平台 多人开发服务器,有时自己运行一个进程在服务器上,但未知原因导致停止运行了,需要添加一个定时任务,用于监控指定进程是否运行 方法 一个通用的方法,以便使用在不同项目中. 思路:定时 ...

  6. Linux下开发Windows平台运行的程序 - MinGW

    开源不乏神人,于是有了MinGW(Minimalist GNU for Windows),又称mingw32,是将GCC编译器和GNU Binutils一直到Win32平台下,包含一系列头文件.库和可 ...

  7. linux下使用gcc编译运行C程序

    gcc(GNU Compiler Collection)是Linux下最常用的C语言编译器,是GNU项目中符合ANSI C标准的编译系统,能够编译用C.C++和Object C等语言编写的程序.  在 ...

  8. 在ubunt14.04(linux)下利用cmake编译运行opencv程序

    今天在电脑上安装好了opencv环境,迫不及待的想写个程序来测试一下.但是在windows下我们用vs等集成开发工具.可是在linux下我们应该怎么办呢? 这里我们用了opencv推荐的cmake来编 ...

  9. Linux 判断系统任务是否正在运行

    #!/bin/bash if ps -ef|grep "php index"|egrep -v grep >/dev/null then >& >> ...

随机推荐

  1. yum ftp本地源

    一. 准备工作1. 安装系统centos7.32. 环境 10.10.10.14 controller-1 10.10.10.15 computer-1 3. 在14主机上安装FTP服务yum ins ...

  2. python操作csv

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #CSV文件的写入(按行写入) import csv #csv文件,是一种常用的文本格式,用以存储表格数据,很 ...

  3. maven项目将web2.5改为web3.1

    用maven构建的web项目默认的web.xml为2.3的版本,而我们需要更改为我们想要的版本(3.1). 在这里有两种方式更改web.xml的版本: 第一种: 将项目切换为navigator视图,然 ...

  4. myBaits association的使用

    转自:https://blog.csdn.net/victor_cindy1/article/details/50194879 >

  5. ruby 功力修炼

    建表 ActiveRecord::Schema.define do drop_table :hosts if table_exists? :hosts create_table :hosts do | ...

  6. js调用activeX插件 报异常:TypeError:对象不支持 属性方法

    部署之后的js网页如果调用没有签名的 ocx/dll 插件的话会报异常:TypeError:对象不支持 “init” 属性方法 (init为插件公开的方法) 但是如果写一个htm本地文件去调用插件,和 ...

  7. Thread(线程)三

    今天我们继续接着线程讲讲,上一章提到一下task概念, 首先接着task继续往下讲,在前章节提到过Thread怎么实现其他线程完成后再让主线程继续执行的功能,那么如果Task也需要线程等待事件,该怎么 ...

  8. Spring DI的配置使用

    1.1.1 依赖和依赖注入Spring IOC容器的依赖有两层含义:Bean依赖容器和容器注入Bean的依赖资源:a.Bean依赖容器:也就是说Bean要依赖于容器,这里的依赖是指容器负责创建Bean ...

  9. Unable to resolve module `../res/images/ic_popular.png`

  10. 《Android Studio实用指南》7.1 AndroidStudio代码检查工具概述

    本文节选自<Android Studio实用指南> 作者: 毕小朋 目前本书已上传到百度阅读, 在百度中搜索[Anroid Studio实用指南]便可以找到本书. Android Stud ...