So I was thinking about this some more while waiting for my wife to pick me up. I'm not crazy about making system calls, but it's not a critical feature and I could error-check for the existence of the system commands and if it's not present, I can just make an arbitrary decision. But here was my idea:
sleep 10 | perl -e '$ppid=getppid();$sibs=`pgrep -P $ppid`;print("MY P +ID: $$\nPARENT: $ppid\nSIBLINGS: $sibs\n")' MY PID: 79496 PARENT: 563 SIBLINGS: 79495
It doesn't work all the time. If I run a short command, like echo, I don't get that PID:
echo test | perl -e '$ppid=getppid();$kids=`pgrep -P $ppid`;print("MY +PID: $$\nPARENT: $ppid\nSIBLINGS: $kids\n")' MY PID: 79493 PARENT: 563 SIBLINGS:
Plus, this doesn't tell me about whether or not I'm running inside a shell script. I couldn't find a perl module that does what pgrep does.

In reply to Re: Can a script tell if it is being run from inside a script versus in an interactive terminal session? by hepcat72
in thread Can a script tell if it is being run from inside a script versus in an interactive terminal session? by hepcat72

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.