14

We can install GNU coreutils via brew. But there's no ps in the utils. Can we use gnu ps in OS X?

I'd like to use GNU ps as it has more options and features.

  • have you tried running ps or ps -ef in a terminal on OSX? works for me on OSX 10.7.5 with no modifications, on two different machines. It's in /bin/ps – jammypeach May 19 '15 at 15:06
  • Yup, I know, I wanted to use GNU ps because it has more options and features. – Sanghyun Lee May 19 '15 at 15:08
  • ah OK, sorry I didn't realise that from the question as stated. I'd suggest including that somewhere, incase anyone else thinks the same as me - good luck with finding a solution – jammypeach May 19 '15 at 15:09
  • Thank you for the suggestion. I added more explanation about that. – Sanghyun Lee May 19 '15 at 15:33
20

There is no portable ps program. The ps command available on linux is, as others have mentioned, from the "procps" package. The reason why this cannot be ported to OSX is because Linux and OSX kernels do not expose this information in the same way. Linux uses a pseudo-filesystem in /proc, whereas OSX uses the sysctl function. Other systems may use either mechanism but provide data in a different format, or may require programs like ps to read directly from the kernel's memory.

In general there is no standard for how process information is available to programs like ps and top; so the program has to be designed for a specific operating system. If there is a specific feature missing from the OSX ps, you'll have to find another program that can do it, or write one yourself (look at the sysctl manual, in particular KERN_PROC as a starting point), or modify the existing ps command to add the feature.

Alternately, if you can get what you need by parsing the output of the ps command itself, you may be able to write a portable program - the output with the -o option is reasonably reliable across platforms, particularly if you refer to the UNIX standard for the column names to use.

  • Is the /proc filesystem the only method the Linux kernel provides for getting a list of processes, or are there also separate system calls which provide that information? – Tanner Swett May 19 '15 at 16:18
  • 1
    @TannerSwett I don't think so. Before /proc was implemented, the ps command on linux worked by reading from /dev/kmem and /dev/swap. – Random832 May 19 '15 at 16:24
7

No - since it does not exist. As to why there is no builtin ps in GNU’s coreutils package, see this answer on the Unix & Linux Forums.

The best alternative formula available via Homebrew is psgrep:

psgrep is a small Bash shell script that searches the process list (as obtained by ps(1) ) using the awesome utility grep(1) for its power.

That said, you can still use psgrep to behave as OS X’s ps would. For example:

   OPTIONS
   -a     Search the process list using BSD's "ps aux" format. This option
          includes all users' processes in the search.

   -b     Search the process list using BSD's "ps  ux"  format  (default).
          This option only includes the running user's processes.

pgrep is also available via brew, which is syntactically closer to ps, but less efficient than psgrep:

psgrep(1) is more useful than pgrep(1) because not only can it search the process list and return a PID, it can give more useful information such as its UID, GID, memory/CPU usage, niceness, and anything else supported by ps.


All emphasis mine.

  • 2
    pgrep is part of recent versions of OS X as well – nohillside May 19 '15 at 9:51
  • @patrix agh! good point, confirmed: type -a pgrep pgrep is /usr/local/bin/pgrep pgrep is /usr/bin/pgrep – njboot May 19 '15 at 10:07
3

ps is not part of GNU coreutils according to Wikpedia. The version that comes with my Linux distribution seems to be from procps, but it seems like there is no formula for it in homebrew. There are formulas for pstree which can give you great tree views, and also htop is another good process viewer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .