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. java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

    写了一个单元测试test来启动activiti,controller放在src/main/java根目录下,test对应也放在src/test/java下,结果报错: java.lang.Illega ...

  2. java8集合--LinkedList纯源码

    package Queue; import java.util.*; import java.util.function.Consumer; /** * 双端队列主要实现list接口和Deque接口, ...

  3. iOS-静态库,动态库,framework浅析(三)

    创建framework静态库 第一步,新建项目 新建项目.png 第二步,删除系统默认创建的[FMDB.h]和[FMDB.m]文件,导入需要打包的源文件. 导入源码后的工程.png 第三步,修改项目配 ...

  4. [administrative] windows 下制作USB启动盘的工具

    arch魔教的文档:  https://wiki.archlinux.org/index.php/USB_flash_installation_media windows 下的 dd: https:/ ...

  5. linux关闭的时候出现异常: java.net.ConnectException: 拒绝连接 (Connection refused)

    这个时候: 需要先把java进程杀死. 然后再重新启动. 杀死进程: ps -aux | grep java 然后kill -9 进程 然后再重新启动.

  6. postman客户端的安装与使用

    安装 首先下载蓝灯,为FQ做准备 登录github,输入https://github.com/getlantern/lantern,找到下载链接下载 安装并成功启动蓝灯 登录谷歌浏览器的应用市场,搜索 ...

  7. python 遇到的问题及解答

    1.使用pip安装python 模块 打开cmd 输入pip install *,如pip install numpy    等待安装(如下) C:\WINDOWS\System32>pip i ...

  8. 前端 HTML body标签相关内容 常用标签 超链接标签 a标签

    超链接标签 <a> 超级链接<a>标记代表一个链接点,是英文anchor(锚点)的简写.它的作用是把当前位置的文本或图片连接到其他的页面.文本或图像,也可以是相同网页上的不同位 ...

  9. 这可能是由于 CredSSP 加密 Oracle 修正。

    1.Win+R 输入regedit打开注册表 找到对应的以下目录 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Polici ...

  10. ArcGIS工具备忘

    1.Repair Geometry (Data Management) 几何图形修复,比如面图层不满足节点坐标逆时针 2.Raster Domain (3D Analyst) 获取栅格范围 3.Int ...