如何通过提供在Mac OS X的进程名得到一个进程的PID? [英] How to get the PID of a process by giving the process name in Mac OS X ?

查看:1025
本文介绍了如何通过提供在Mac OS X的进程名得到一个进程的PID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个脚本监视任何给定的过程中的CPU和MEM。为此我需要在这个过程中的名义发送作为一个命令行参数进行监控。例如。

I am writing a script to monitor the CPU and MEM of any given process. For that i need to send in the name of the process to be monitored as a commandline argument. For example.

./monitorscript <pname>

我需要得到进程的PID在脚本中,这样我可以使用 PS -p&LT; PID&GT; 里面。

我如何得到一个进程的PID给予其进程名称?

How do i get the pid of a process given its process name?

据我了解,有可能是在同一个名称的多个进程。我只是想获得的第一道工序出名单。

I understand that there might be multiple processes in the same name. I just want to get the first process out of that list.

推荐答案

以上大部分是正确的,只是需要一些调整在Mac OSX上的不同参数的答案。

The answer above was mostly correct, just needed some tweaking for the different parameters in Mac OSX.

ps -A | grep -m1 firefox | awk '{print $1}'

这篇关于如何通过提供在Mac OS X的进程名得到一个进程的PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆