Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Controlling Terminal Accuracy

by steves (Curate)
on Oct 02, 2004 at 13:29 UTC ( #395882=perlquestion: print w/replies, xml ) Need Help??

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

I have a desire to know what the controlling terminal is for my process. As a test, I wanted to see some differences between jobs I start from a UNIX shell and those I start as UNIX cron jobs. Using Proc::ProcessTable gives me the results I would expect: The shell jobs, no matter how I start or background them, have a ttynum value greater than zero. For cron jobs ttynum is -1. However, using the POSIX ctermid function, I get /dev/tty no matter how the jobs is started.

This is Solaris 2.8, Perl 5.6.1. I'd also use it under Perl 5.8.0 but I haven't tried it there yet.

Update: It looks like ctermid just gives you back a path name you can use to open a controlling terminal. For the cron jobs, attempts to open that device fail. That tells me what I need to know.

Replies are listed 'Best First'.
Re: Controlling Terminal Accuracy
by JaWi (Hermit) on Oct 02, 2004 at 14:32 UTC
    You can use the -t operator to check whether your script is connected to a TTY. At least under my Debian system, I get a positive result (1) for the -t operator for a job started from the console, and nothing for 'crontabbed jobs'.


    -- JaWi

    "A chicken is an egg's way of producing more eggs."

      That's slightly different than the controlling terminal. The controlling terminal (in UNIX) is the terminal the job is associated with for signals, but not necessarily the terminal the job is connected to. For example, running a command pipeline or redirected command from the shell will make the process not have a terminal connected to it, but it will still have a controlling terminal. A cron job will have neither a connected terminal or a controlling terminal. The difference is subtle but can be important for things like daemons.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2022-09-29 03:55 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.