From roebuck at mdanderson.org  Wed Feb  7 06:56:51 2007
From: roebuck at mdanderson.org (Paul Roebuck)
Date: Tue, 6 Feb 2007 23:56:51 -0600 (CST)
Subject: [Rd] Help with OS X (BSD) ps command
In-Reply-To: <xmr64akoe2l.fsf@mralx1.rsma.frb.gov>
References: <xmr64akoe2l.fsf@mralx1.rsma.frb.gov>
Message-ID: <Pine.OSF.4.58.0702062303530.122756@wotan.mdacc.tmc.edu>

On Fri, 2 Feb 2007, Jeffrey J. Hallman wrote:

> My fame package has a function that checks to see if
> a FAME SERVER process is already running.  On Linux,
> I can do this in one of two ways:
>
>   pid <- Sys.getpid()
>   user <- Sys.info()["user"]
>
>   cmd <- paste("pgrep -fU", user, "-P", pid, "'FAME SERVER'")
>   fameRunning <- as.logical(length(system(cmd, intern = T)))
>
> or I can use
>
>   cmd <- paste("ps -ef | grep", user, "| grep", pid,
>                  "| grep -v grep | grep -c 'FAME SERVER'")
>   fameRunning <- as.logical(as.numeric(system(cmd, intern = T)))
>
> Mac OS X does not have pgrep, and being a BSD
> derivative, takes different arguments for the 'ps'
> command.  I don't have access to a BSD machine. Can
> someone who does tell me the correct invocation of
> 'ps' to see if 'user' is running a 'FAME SERVER'
> process with the R process as its parent process?
>
> While FAME is not officially supported on OS X, I
> am told that it can be made to work there.  Had I
> not heard this, of course, I could just answer FALSE
> for OS X and be done with it.

<<untested>>
cmd <- paste("ps -o user,ppid,command", "| ",
             "grep", user, "| ",
             "grep", pid, "| "
             "grep -c '[F]AME SERVER'")

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)



[Rd] Help with OS X (BSD) ps command
Paul Roebuck