热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Linux/UNIX:Findoutordetermineifprocesspidisrunning

http:www.cyberciti.bizfaqhowto-display-process-pid-under-linux-unixHowdoIfindoutmyprocessi

http://www.cyberciti.biz/faq/howto-display-process-pid-under-linux-unix/


How do I find out my process is running on a Unix-like operating systems? How do I get the pid number for particular process on a Linux operating systems using bash shell?

A PID is an acronym for process identification number on a Linux or Unix-like operating system. A PID is automatically assigned to each process when it is created. A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system.
Tutorial details  
Difficulty Easy (rss)
Root privileges No
Requirements None
Estimated completion time 2m

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

Task: Find out process pid

Simply use ps command as follows:
ps aux | grep {process-name}

For example find out if mysqld process (mysqld pid) is running or not:
$ ps aux | grep mysqld
Sample outputs:

mysql 28290 1.1 2.7 340496 56812 ? Sl Jul31 348:27 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock

Find the process ID of a running program using pidof

pidof command finds the process id’s (pids) of the named programs. It prints those id’s on screen. This program is on some systems used in run level change scripts, especially when the system has a System-V like rc structure. In that case these scripts are located in /etc/rc?.d, where ? is the runlevel. If the system has a start-stop-daemon (8) program that should be used instead.
# pidof mysqld
Sample outputs:

28290

Find PID using pgrep command

The pgrep command searches the running system and shows the process IDs of all processes that match the given criteria. The syntax is:
pgrep {processNameHere}
pgrep firefox
pgrep httpd
pgrep nginx

Sample outputs:

4241

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?


{ 19 comments… add one }

  • surendra kumar August 27, 2007, 8:14 am

    hay man you can use pgrep also know?
    why ps -aux | grep process name?
    u can use pgrep like this
    pgrep process name
    pgrep httpd
    pgrep named
    pgrep firefox
    etc
    if any special about your command just give me info related to it

  • Adrian B. February 10, 2009, 9:27 am

    Thanks Surendra, damn good tips

  • Adrian B. February 10, 2009, 9:28 am

    you can also use this :
    $>pkill -f cruisecontrol
    in a cruisecontrol process which runs under java. -f does a substring search of the process string.

  • lala September 20, 2009, 7:33 pm

    man, u guys rock, trust me it helps so much, when my maya hangs.
    special thanks: adrian B, pkill -f maya: wow, toogood

  • Rakesh October 2, 2009, 11:40 am

    Hi .

    I have a probleam . when i start mysql it is showing MySQL manager or server PID file could not be found! [FAILED] . Starting MySQL/etc/init.d/mysql: line 159: kill: (5984) – No such process .how to solve the probleam. if any one know plz help me

  • subramanya April 23, 2010, 8:38 am

    Thank you very much for the info.. it works for me..

  • Aaron October 20, 2010, 4:00 am

    i tried using kill(pid,0) to test whether the process is existent, need to include

    Aaron

  • mohsin November 29, 2010, 8:19 am

    when i reconfigure (squid -k reconfigure) squid i got error.
    like this
    squid: ERROR: Could not send signal 1 to process 6471: (3) No such process
    how i can remove this error please help me.

    Thanks in advance

  • Pinoy June 4, 2011, 5:12 pm

    hanks ive been searching the net on how to find the pid of a process and this post solve my problem. thank you

  • Mikkel September 22, 2011, 9:02 pm

    Bear in mind that the command itself can show up in the results. For instance:

    mikkel@www ~ $ ps aux | grep ntp
    root 20417 0.0 0.0 4408 1316 ? Ss 17:30 0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid
    mikkel 20429 0.0 0.0 2064 572 pts/0 S+ 17:30 0:00 grep --colour=auto ntp

    If you only see the grep command listed, that means the named command is not running.

  • Amensan November 6, 2011, 5:27 pm

    Hi,

    I still can’t see my pid number for my postfix services. can’t find that. Help me. Thanks.

    Using: Linux server 11.04

  • SALIM November 15, 2011, 9:13 am

    why ? mark indicating ?? while each ps -ef |grep some process

  • kamal March 14, 2012, 6:53 am

    Hii,
    im facing one problem with pgrep command
    I want to display the PID of process with greping on process name..im using this command for that:
    pgrep -lfu $UID | grep -i AddUser | grep -v grep | grep bash | tr -s ” ” | cut -d ” ” -f1
    but since the path of process AddUser is too long..the output of pgrep does not shows the fullname of process instead it crops the process name and displays only first 3 chars…Any idea to avoid cropping of process name

  • hari April 3, 2012, 9:45 am

    thanku fr d infr…

  • mullai June 1, 2012, 8:02 am

    hello.i want the command for taking login name as a command line argument in linux for shell program

  • Himal February 6, 2013, 5:02 pm

    hello, What does ps – HI do? What is the meaning of this command?

  • oluc May 2, 2013, 8:20 am

    The process could be running (it has a pid) but stopped (kill -STOP $pid) (it is not actually running).

  • devender shekhawat September 27, 2014, 7:01 pm

    I have a process PID i want to check this PID is for which process & the process is running or not.please explain with example

  • Rabindra kumar February 9, 2015, 4:28 am

    Hi All I want to know how many jobs are running on a particular server. So can anyone help me providing the command so that I could able to check how many jobs are running in the server and log status as well






推荐阅读
  • http:blog.csdn.netzeo112140articledetails7675195使用TCPdump工具,抓TCP数据包。将数据包上传到PC,通过Wireshark查 ... [详细]
  • CentOS 7 默认安装了 MariaDB,作为 MySQL 的一个分支。然而,出于特定需求,我们可能仍需在系统中安装 MySQL。本文将详细介绍如何通过 Yum 包管理器在 CentOS 7 上安装 MySQL,并提供一些常用的 MySQL 命令。 ... [详细]
  • Android 构建基础流程详解
    Android 构建基础流程详解 ... [详细]
  • 尽管Medium是一个优秀的发布平台,但在其之外拥有自己的博客仍然非常重要。这不仅提供了另一个与读者互动的渠道,还能确保您的内容安全。本文将介绍如何使用Bash脚本将Medium文章迁移到个人博客。 ... [详细]
  • 本文介绍了如何在Android应用中通过Intent调用其他应用的Activity,并提供了详细的代码示例和注意事项。 ... [详细]
  • 本文介绍了一种通过设置主题(Theme)来实现快速启动的Android引导页,并详细说明了如何避免因不同屏幕分辨率导致的图片拉伸问题。 ... [详细]
  • 关于进程的复习:#管道#数据的共享Managerdictlist#进程池#cpu个数1#retmap(func,iterable)#异步自带close和join#所有 ... [详细]
  • Ubuntu 环境下配置 LAMP 服务器
    本文详细介绍了如何在 Ubuntu 系统上安装和配置 LAMP(Linux、Apache、MySQL 和 PHP)服务器。包括 Apache 的安装、PHP 的配置以及 MySQL 数据库的设置,确保读者能够顺利搭建完整的 Web 开发环境。 ... [详细]
  • Linux 实时网络流量监控工具 iftop 使用指南
    iftop 是一款强大的实时网络流量监控工具,通过安装和配置该工具,用户可以实时监控网络接口的流量情况。本文将详细介绍 iftop 的安装步骤、常用参数及操作命令。 ... [详细]
  • 本文介绍了如何在 Spring Boot 项目中使用 spring-boot-starter-quartz 组件实现定时任务,并将 cron 表达式存储在数据库中,以便动态调整任务执行频率。 ... [详细]
  • 本文详细介绍了如何在Linux系统(以CentOS为例)上彻底卸载Zimbra邮件系统,包括停止服务、删除文件和用户等步骤。 ... [详细]
  • 开机自启动的几种方式
    0x01快速自启动目录快速启动目录自启动方式源于Windows中的一个目录,这个目录一般叫启动或者Startup。位于该目录下的PE文件会在开机后进行自启动 ... [详细]
  • 本文介绍了 Linux 系统中用于定期执行任务的 cron 服务及其配置方法。通过 crond 和 crontab 命令,用户可以轻松地安排系统和用户级别的周期性任务。 ... [详细]
  • 本文详细介绍了在 Ubuntu 系统上搭建 Hadoop 集群时遇到的 SSH 密钥认证问题及其解决方案。通过本文,读者可以了解如何在多台虚拟机之间实现无密码 SSH 登录,从而顺利启动 Hadoop 集群。 ... [详细]
  • Python错误重试让多少开发者头疼?高效解决方案出炉
    ### 优化后的摘要在处理 Python 开发中的错误重试问题时,许多开发者常常感到困扰。为了应对这一挑战,`tenacity` 库提供了一种高效的解决方案。首先,通过 `pip install tenacity` 安装该库。使用时,可以通过简单的规则配置重试策略。例如,可以设置多个重试条件,使用 `|`(或)和 `&`(与)操作符组合不同的参数,从而实现灵活的错误重试机制。此外,`tenacity` 还支持自定义等待时间、重试次数和异常处理,为开发者提供了强大的工具来提高代码的健壮性和可靠性。 ... [详细]
author-avatar
jzcoijawlkmlzkm_307
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有