Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Detecting forground and background process

by astroboy (Chaplain)
on Jul 20, 2010 at 03:23 UTC ( [id://850341]=perlquestion: print w/replies, xml ) Need Help??

astroboy has asked for the wisdom of the Perl Monks concerning the following question:

Hi - is there any OS-generic way (Windows & *nix) - using a CPAN module or not - to tell from inside my script whether it's running in the foreground or the background?
  • Comment on Detecting forground and background process

Replies are listed 'Best First'.
Re: Detecting forground and background process
by BrowserUk (Patriarch) on Jul 20, 2010 at 08:41 UTC

    If you are using Jenda's Win32::Deamon::Simple, then test the global $CMDLINE. If not, look at the BEGIN block in that module for how he decides whether to set it true or false.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Detecting forground and background process
by ikegami (Patriarch) on Jul 20, 2010 at 03:41 UTC
    That concept doesn't exist in Windows.

      Ok - well for my purposes, let's say we're not running in a console. We could be called from a Win32::Daemon service. So I'm trying to determine whether I'm running in a console (or terminal session) or not. So let me rephrase, The solution doesn't need to be generic. I can just have a condition to see if I'm running on Windows or *nix, and then do the appropriate check ... but I still need to know what the check would be

        Maybe you could check if STDIN is opened to a terminal/console:

        if (-t STDIN) { ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://850341]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found