Linux 判断进程是否已经运行的程序
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 判断进程是否已经运行的程序的更多相关文章
- linux根据进程号PID查找启动程序的全路径
linux根据进程号PID查找启动程序的全路径 2014-01-25 11:09 18629人阅读 评论(0) 收藏 举报 分类: Linux系统管理(29) 版权声明:本文为博主原创文章,未经博 ...
- Linux查看进程启动时间和运行多长时间
Linux 查看进程启动时间和运行多长时间 启动时间 ps -eo lstart 运行多长时间 ps -eo etime -bash-4.1$ ps -eo pid,lstart,etime | gr ...
- 在linux下安装eclipse以及运行c++程序的安装步骤
1. 下载jre,eclipse,cdt 其中jre是java运行环境,eclipse需要先装jre,才可能运行,cdt是在eclipse中运行c\c++程序的插件. 下载jre 网址是: ...
- 如何在linux下安装jdk并运行java程序
一.进入root 大家可以看到我这里用的是CentOS 6.5 系统 二.测试网络与YUM是否可用 1.测试网络 ping www.baidu.com,如下图就是通了 参考: 一.JDK安装1.lin ...
- Linux 判断进程是否运行
问题 linux平台 多人开发服务器,有时自己运行一个进程在服务器上,但未知原因导致停止运行了,需要添加一个定时任务,用于监控指定进程是否运行 方法 一个通用的方法,以便使用在不同项目中. 思路:定时 ...
- Linux下开发Windows平台运行的程序 - MinGW
开源不乏神人,于是有了MinGW(Minimalist GNU for Windows),又称mingw32,是将GCC编译器和GNU Binutils一直到Win32平台下,包含一系列头文件.库和可 ...
- linux下使用gcc编译运行C程序
gcc(GNU Compiler Collection)是Linux下最常用的C语言编译器,是GNU项目中符合ANSI C标准的编译系统,能够编译用C.C++和Object C等语言编写的程序. 在 ...
- 在ubunt14.04(linux)下利用cmake编译运行opencv程序
今天在电脑上安装好了opencv环境,迫不及待的想写个程序来测试一下.但是在windows下我们用vs等集成开发工具.可是在linux下我们应该怎么办呢? 这里我们用了opencv推荐的cmake来编 ...
- Linux 判断系统任务是否正在运行
#!/bin/bash if ps -ef|grep "php index"|egrep -v grep >/dev/null then >& >> ...
随机推荐
- Less、Sass/Scss
一.Less.Sass/Scss是什么? 1.Less: 是一种动态样式语言. 对CSS赋予了动态语言的特性,如变量.继承.运算.函数. Less 既可以在客户端上运行 (支持IE 6+, Webki ...
- linux网络监视器
vnstat iftop nethogs dig ipcalc
- 说说JDK中的List-ArrayList、Vector、LinkedList
为方便开发人员,JDK提供了一套主要数据结构的实现,比如List.Map等.今儿说说List接口. List接口的一些列实现中,最常用最重要的就是这三个:ArrayList.Vector.Linked ...
- 微信小程序从入坑到放弃之坑十二:navigator无法跳转的坑
转自:http://www.yilingsj.com/xwzj/2018-11-25/weixin-miniprogram-navigator.html 微信小程序中的页面跳转用navigator就行 ...
- C#与U3D中字符串尾0
static void TestChar0() {//注意字符串中0和\0的区别,如 s1="h0ello", s2 = "h\0ello" //s2中的\0是 ...
- iOS设计模式(01):观察者
iOS设计模式(01):观察者 iOS-Observer-Pattern 什么是观察者模式 什么是观察者模式?你曾经订阅过报纸吗?在订阅报纸的时候,你不用去任何地方,只需要将你的个人地址信息以及订阅信 ...
- centos7 时间修改
转子 http://blog.csdn.net/kuluzs/article/details/52825331 在CentOS 6版本,时间设置有date.hwclock命令,从CentOS 7开始, ...
- drbd mysql
使用drbd前 升级内核 yum install kernel* 重启 4.1.准备: 两个节点ha-node1和ha-node2均按照centos7.0系统,每个节点两块磁盘,一块用作根分区一块用作 ...
- spring bean单例注入与用单例模式通过class.getinstance()区别?
1.action的某个方法中,用以下代码获得redis单例实例 RedisDelegate redisDelegate = RedisDelegate.getInstance(); redisDele ...
- Codeforces 1154F (DP)
题意:有一个人去买铲子,他需要买正好k把.每把铲子有个标价,并且每把铲子最多只能被买一次.有m种优惠方案,每个优惠方案xi, yi是指如果这次恰好购买了xi把铲子,那么这次购买的铲子中最便宜的yi把将 ...