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

I am using top command in HP-UX. To come out of top , i need to use Ctrl+z. My problem is : I will call the top command from my perl script and write the same in some file, but I am cluelss how to incorporate the Ctrl+z in perl to terminate the top function. Please show me some path ....
  • Comment on incorporate Ctrl+z of unix in Perl code

Replies are listed 'Best First'.
Re: incorporate Ctrl+z of unix in Perl code
by JavaFan (Canon) on Feb 02, 2011 at 11:44 UTC
    Ctrl+z is the way to get out of top on HP-UX? It's not 'q' like any other top? In most terminals/shells, 'ctrl+z' is the suspend key, which sends a SIGSTOP to the process. This suspends the process - it doesn't terminate it. Suspending means the process no longer gets a timeslice on the CPU - and will last until the process is killed, or a SIGCONT.

    But regardless, if you run top as system "top", it ought to be running in the foreground, and all keyboard input should be directed to it. So, if indeed, on your system, 'ctrl+z' isn't the suspend key (check stty -a), but the normal way to stop top, it ought to work.

Re: incorporate Ctrl+z of unix in Perl code
by MidLifeXis (Monsignor) on Feb 02, 2011 at 12:17 UTC

    Unless your stty settings are all messed up very different from typical, C-z is not how you get out of top. As mentioned previously, 'q' will quit top, and batch mode with the number of iterations flag is the "correct" way to do it. See man top at a command shell for details, or check the matrix (pdf - witw) for where hp has them shuffled away at this point in time.

    Update (2011-02-03 04:48:30 -0600): Spellcheck.

    --MidLifeXis

Re: incorporate Ctrl+z of unix in Perl code
by Utilitarian (Vicar) on Feb 02, 2011 at 10:59 UTC
    Doesn't hp-ux top support the -b (batch) option when incorporating into scripts and the -n option to specify the number of itterations
    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."