[Thread Prev][Thread Next][Index]
Re: process ID, collisions
Hi all,
Just following up on an old thread -- here's the most compact way I've
found to get the process ID (PID) of a Ferret session:
let pid = `{spawn:"perl -e 'print getppid,0'"}`
No shell scripts required. The trailing 0 is just an arbitrary character
to prevent the last digit of the PID from getting chomped by Ferret. (It
seems Ferret expects the shell output to contain a trailing newline, so it
eats the last character. I can't think of any way to tack a newline onto
the end of the perl output here, because Ferret chokes on any quotes,
backslashes, or semicolons inside this spawn construct.)
Suggestion to the developers: in a future version, could we add the
session PID to the list of automatic symbols in Ferret? I.e. in the same
way we now have "FERRET_PLATFORM", we could have a "FERRET_PID". Ferret
could call Joe Sirott's program (below) to get the PID at startup.
Andrew
On Mon, 26 Aug 2002, Andrew Wittenberg wrote:
> Inspired by a suggestion from Joe Sirott, here's a platform-independent
> way to get the process identification (PID) of Ferret. One simply needs
> to obtain the PARENT process identification (PPID) of the shell launched
> by the SPAWN command. So create a Perl script "ppid":
>
> #!/usr/bin/perl
> print getppid . "\n";
>
> and place it in a location accessible to the Ferret SPAWN command (e.g. in
> your PATH). Then access the PID in Ferret v5.4x using
>
> yes? let pid = {spawn:"ppid"}
>
> If your system doesn't have Perl, see Joe's C program "ppid.c" below;
> you'll need to compile it separately for each platform on which you run
> Ferret.
>
> Cheers,
>
> Andrew
>
> ----------------------------------------------------------------
>
> Date: Mon, 19 Aug 2002 16:45:38 -0700
> From: Joe Sirott <sirott@pmel.noaa.gov>
> Subject: Re: process ID, collisions
>
> If your shell doesn't support a method for returning the parent process
> id, and you don't want to hassle with external functions, it's trivial to
> write a program to return it. I've included it below. Compile it with:
>
> gcc -o ppid ppid.c
>
> and call it from Ferret as:
>
> sp ppid
>
> #include <sys/types.h>
> #include <unistd.h>
> #include <stdio.h>
>
> int main() {
> printf("%d\n",getppid());
> }
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement