kill -0 pid

sending the signal 0 to a given PID just checks if any process with the given PID is running and you have the permission to send a signal to it.

$ man 2 kill

If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID.

check exists, return 0

$ pgrep httpd
46775
$ kill -0 46775
$ echo $?
0

check non-exists, return 1

$ kill -0 999999899
bash: kill: (999999899) - No such process
$ echo $?
1

kill process id stored in .pid file

#!/bin/sh
pid_file=/var/run/process.pid kill -0 $(cat $pid_file) 2>/dev/null if [ $? -eq 0 ]; then
kill $(cat $pid_file)
fi

check process id exists的更多相关文章

  1. [jQuery] check if an id exists - Google 网上论坛

    [jQuery] check if an id exists - Google 网上论坛 From: http://docs.jquery.com/Frequently_Asked_Questions ...

  2. Process ID, Process handle, Window handle

    http://forums.codeguru.com/showthread.php?392273-RESOLVED-How-to-get-window-s-HWND-from-it-s-process ...

  3. 查看进程id, 父进程id _How do I get the parent process ID of a given child process?

    How to get parent pid from a given children pid? I know I can mannully check it under /proc, I am wo ...

  4. Transaction (Process ID xxx) was deadlocked on lock

    Transaction (Process ID 161) was deadlocked on lock | communication buffer resources with another pr ...

  5. 多线程处理sql server2008出现Transaction (Process ID) was deadlocked on lock resources with another process and has been chose问题

    多线程处理sql server2008某个表中的数据时,在Update记录的时候出现了[Transaction (Process ID 146) was deadlocked on lock reso ...

  6. loadrunner录制时弹出invalid application path!please check if application exists对话框

    问题:oadrunner录制时弹出invalid application path!please check if application exists对话框 原因:IE浏览器地址不对,需要手动重新选 ...

  7. mysql无法启动 mysqld process already exists

    1.提示:A mysqld process already exists ps 命令用于查看当前正在运行的进程. grep 是搜索 例如: ps -ef | grep mysql 表示查看所有进程里 ...

  8. java代码中获取进程process id(转)

    另一方面,线程ID=进程ID+内部线程对象ID并不成立,    参考: blog.csdn.net/heyetina/article/details/6633901     如何在java代码中获取进 ...

  9. 进程ID[PID(Process ID)]与端口号[(Port ID)]的联系

    1.首先声明一点:PID不是端口(port id),而是Process ID进程号的意思. 2.那么,什么是进程号? 采集网友的意见就是: 进程号,是系统分配给么一个进程的唯一标识符.PID就是各进程 ...

随机推荐

  1. weblogic初学笔记2-在Linux上部署项目

    一.这两天在做部署项目到Linux服务器上. 网上有用war包部署的,也有把war包解压之后部署的.比如:http://www.cnblogs.com/xdp-gacl/p/4143413.html ...

  2. 洛谷P1126 机器人搬重物【bfs】

    题目链接:https://www.luogu.org/problemnew/show/P1126 题意: 给定一个n*m的方格,机器人推着直径是1.6的球在格子的线上运动. 每一秒钟可以向左转,向右转 ...

  3. Java编程:删除 List 元素的三种正确方法

    删除 List 中的元素会产生两个问题: 删除元素后 List 的元素数量会发生变化: 对 List 进行删除操作可能会产生并发问题: 我们通过代码示例演示正确的删除逻辑 package com.ip ...

  4. 用CountDownLatch提升请求处理速度

    countdownlatch是java多线程包concurrent里的一个常见工具类,通过使用它可以借助线程能力极大提升处理响应速度,且实现方式非常优雅.今天我们用一个实际案例和大家来讲解一下如何使用 ...

  5. MyBatis时间比较

    <if test="submitTime!=null and submitTime!=''"> AND DATE_FORMAT(sc.submit_time, '%Y- ...

  6. AngularJS 常用的功能

    第一 迭代输出之ng-repeat标签ng-repeat让table ul ol等标签和js里的数组完美结合 例: <ul><li ng-repeat="person in ...

  7. 几个linux内核参数

    raid=noautodetec libata.force=3.0G mem=1G 不检测raid, sata限制3.0G 内存限制1G https://serverfault.com/questio ...

  8. Laravel 5.2 INSTALL- node's npm and ruby's bundler.

    https://getcomposer.org/doc/00-intro.md Introduction# Composer is a tool for dependency management i ...

  9. a buzzword to refer to modern Web technologies

    https://html.spec.whatwg.org/multipage/introduction.html#is-this-html5? HTML Living Standard — Last ...

  10. 原码,补码,反码的概念及Java中使用那种存储方式

    原码,补码,反码的概念及Java中使用那种存储方式: 原码:原码表示法是机器数的一种简单的表示法.其符号位用0表示正号,用:表示负号,数值一般用二进制形式表示 补码:机器数的补码可由原码得到.如果机器 ...