Changes to perlfaq8 "How do I find out if I'm running interactively
Steve Peters [Wed, 19 Apr 2006 16:32:26 +0000 (16:32 +0000)]
or not?" suggested by Slaven Rezic in RT #38901: perlfaq8 correction

p4raw-id: //depot/perl@27905

pod/perlfaq8.pod

index 06494e2..d5c63da 100644 (file)
@@ -1005,13 +1005,19 @@ On POSIX systems, you can test whether your own process group matches
 the current process group of your controlling terminal as follows:
 
     use POSIX qw/getpgrp tcgetpgrp/;
-    open(TTY, "/dev/tty") or die $!;
-    $tpgrp = tcgetpgrp(fileno(*TTY));
-    $pgrp = getpgrp();
-    if ($tpgrp == $pgrp) {
-        print "foreground\n";
+    
+    # Some POSIX systems, such as Linux, can be
+    # without a /dev/tty at boot time. 
+    if (!open(TTY, "/dev/tty")) {
+        print "no tty\n";
     } else {
-        print "background\n";
+        $tpgrp = tcgetpgrp(fileno(*TTY));
+        $pgrp = getpgrp();
+        if ($tpgrp == $pgrp) {
+            print "foreground\n";
+        } else {
+            print "background\n";
+        }
     }
 
 =head2 How do I timeout a slow event?