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 >& >> ...
随机推荐
- ncbi API
https://www.ncbi.nlm.nih.gov/sviewer/?db=nuccore&query_key=2&term=DYNLL2&page_size=1& ...
- bower的安装和使用
第一 下载node 网址https://nodejs.org/en/ 安装过程基本直接“NEXT”就可以了. 安装完成之后,我们先检测下NodeJS是否安装成功,cmd命令行中键入: node -v ...
- 搞点事情,使用node搭建反向代理
导语 最近有个需求,需要对业务管理后台的操作记录进行上报.一般这种上报需求都是又后台同学来做比较合适的.但是因为后台人力的原因.这个工作落到了我这个小前端的头上.这里记录下做这个需求踩的一些坑. 一. ...
- 表单验证常用的JS正则表达式
在表单验证中,使用正则表达式来验证正确与否是一个很频繁的操作,本文收集整理了15个常用的javaScript正则表达式,其中包括用户名.密码强度.整数.数字.电子邮件地址(Email).手机号码.身份 ...
- C# XML文件读取
using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; usin ...
- iOS 上的蓝牙框架 - Core Bluetooth for iOS
原文: Core Bluetooth for iOS 6 Core Bluetooth 是在iOS5首次引入的,它允许iOS设备可以使用健康,运动,安全,自动化,娱乐,附近等外设数据.在iOS 6 中 ...
- git 转移
git push --mirror https://github.com/cloud-pi/drbd-docker-plugin.git
- kali linux:wireshark不能被root用户启用的解决方案
启动wireshark后,报错: 该界面提示在init.lua文件中使用dofile函数禁用了使用超级用户运行wireshark.这是因为wireshark工具是使用Lua语言编写的,并且在kali ...
- 高性能Web服务器Nginx的配置与部署研究(14)平滑升级你的Nginx
1.概述(可以直接跳过看第2部分) Nginx方便地帮助我们实现了平滑升级.其原理简单概括,就是: (1)在不停掉老进程的情况下,启动新进程. (2)老进程负责处理仍然没有处理完的请求,但不再接受处理 ...
- Linux 下启动两个tomcat
Linux 下启动两个tomcat 闲来无事学习nginx,想要配置个load balance.可是先决条件是:得有两个web容器.两个电脑是不用想了.只能想办法在一个机器上启动两个tomcat.原以 ...