Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Control+T in Terminal shows time snapshot UNIX
Not sure if this was available before 10.7, but hitting Control+T while running a command in the Terminal will show what process is executing, the load, the PID of the process and its user and kernel time.

I was running a script and accidentally hit Control+T instead of Command+T to create a new tab. I was surprised at what I got. Here is an example of what gets printed:
# buildOrder.py
load: 2.51  cmd: p4 15179 running 0.00u 0.00s
load: 2.23  cmd: p4 17962 waiting 0.01u 0.00s
load: 2.53  cmd: Python 15167 running 94.68u 66.33s
load: 2.60  cmd: Python 15167 running 150.71u 101.82s

[crarko adds: I wasn't able to reproduce this, but it may be due to the briefness of the running command. Give it a try and post a comment about your results. Try it in Snow Leopard too if you can.]
    •    
  • Currently 3.89 / 5
  You rated: 1 / 5 (9 votes cast)
 
[10,926 views]  

Control+T in Terminal shows time snapshot | 22 comments | Create New Account
Click here to return to the 'Control+T in Terminal shows time snapshot' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Control+T in Terminal shows time snapshot
Authored by: woodgie on Jan 27, '12 07:40:15AM

Works for me (10.7.2 and 10.6.8). I tested it running a permissions repair and sure enough, just as the hint said, loads and kernel time.

Interesting, thank you.



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: Djehuti on Jan 27, '12 07:57:58AM

This has actually worked for a while (and probably works on Linux and other unices too). ^T is usually bound to the STATUS character via stty(1). See "man 1 stty". It generates SIGINFO, which most processes ignore. Bash catches it and prints what you saw here.

Some other commands, such as dd, also catch SIGINFO and print useful info when you hit ^T. See "man dd" and scroll down near the bottom under "If dd receives a SIGINFO (see the status argument for stty(1)) signal, ..."



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: arcticmac on Jan 27, '12 07:59:31AM

Yup. Or, for a program that will run long enough to get in a good test, any GUI program will work, since it runs until you quit it from the GUI.

I couldn't resist trying the rest of them to see if there were any other gems I didn't know about. There are all the usuals: Control-M and Control-J create a CR or LF (nominally respectively, though I'm not sure what the practical difference is here). Control-C sends a kill signal to the current process (not a hard kill though). Control-V followed by another letter lets you type other control characters in.

The most interesting one I found though was Control-Z, which (at least for the GUI app that I was trying) sent it a SIGSTOP and detached it from the terminal. SIGSTOP causes most programs to suspend and stop using CPU cycles (resume them with a SIGCONT), and detaching from the terminal is like running followed by an & - the command will still print any output to the terminal, but you have the shell back to do other things while you wait for it to be done.

I was curious if these (control-z, control-t) are Mac OS specific, or typical of most Unix OSes, so I googled, and found this page which is rather informative:
http://web.mit.edu/gnu/doc/html/features_5.html

Edited on Jan 27, '12 08:03:49AM by arcticmac


[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: tofergregg on Jan 27, '12 08:14:36AM

To resume a program you have stopped with ^Z, you have two options:

type "fg" (without the quotes) to reattach it to the terminal (fg stands for "foreground")
type "bg" ("background") to restart the app but still have your terminal



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: arcticmac on Jan 27, '12 08:41:07AM

or something like "killall -CONT processname"



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: pauljlucas on Jan 27, '12 10:59:34AM
Control-M and Control-J create a CR or LF (nominally respectively, though I'm not sure what the practical difference is here).
There is no difference. In ASCII, Control-M (also written ^M) is CR and Control-J (^J) is LF. For example, a pure Unix terminal program can't tell the difference between you typing ^M vs return.
Control-V followed by another letter lets you type other control characters in.
That's more to do with the command-line editor you're currently using than the shell, i.e., that's what you type in vi.
---
- Paul


[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: fido on Jan 28, '12 07:46:13AM
Any Unix program can see the CR's and LF's separately if the programmer chooses. They just have to turn off icrnl or put the tty into raw mode. To say that there is no difference between the two is a little misleading.

Example:

#!/bin/sh
stty -icrnl
echo "Type something, hit control M or enter/return a few times, then hit control J"
read ans
echo "You typed:"
echo $ans | od -a
stty icrnl
Also, control V is the usual setting for the tty's "literal next" (lnext) setting and is not limited to command line editors. Try running a simple command like sleep 30, then hit ^V^M and ^V^J to see that there is a difference between the two.

In Terminal the key labelled "return" will produce the same results as hitting ^M because they're both ways to generate a carriage return (CR). If icrnl is on (see stty -e) then these will be mapped to newlines.

[ Reply to This | # ]

Control+T in Terminal shows time snapshot
Authored by: wallybear on Jan 30, '12 02:11:39PM

"detaching from the terminal is like running followed by an & "

No, it isn't.

Ctrl-Z suspends the process. If you want it to continue in background (like when you use &) you must type
"bg" (=background) on the command line, otherwise typing "fg" it will resume in foreground.
It's useful when you launch a process you want to run in background and you forget to put the "&" at the end of the command: just do Ctrl-Z, type "bg" and you are done.

It's a common feature of Linuxes and BSD.



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: jremmers on Jan 27, '12 08:18:52AM

For long-running commands for testing things like this, "sleep" works well; e.g. "sleep 30" waits for 30 seconds with no i/o, then terminates.



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: mkuron on Jan 27, '12 08:25:47AM
I didn't know this either until a minute ago, but this is a standard feature of unix terminals. Ctrl-T is a special character (take a look at man termios, under Special Characters, STATUS) that sends a SIGINFO signal to the current process (which causes utilities like dd to print their current progress) and prints the current load to the terminal. This should work on any version of Mac OS X, as well as FreeBSD, OpenBSD and pretty much anything derived from the original BSD Unix, but as far as I can tell not on Linux.
Edited on Jan 27, '12 08:26:20AM by mkuron


[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: usovalx on Jan 29, '12 06:18:04PM

It isn't really a standard feauture -- it's only available on BSD-flavoured *nix'es.
It's one of the things I'm missing in linux.



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: wallybear on Jan 30, '12 02:03:05PM

No, Linux has this feature too. At least Debian (hence Ubuntu too), but I think any Linux distro has it.

Edited on Jan 30, '12 02:04:59PM by wallybear



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: jaydisc on Jun 19, '12 05:44:34AM

I've never seen this in Debian. I've always bemoaned its absence.



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: halocaridina on Jan 27, '12 08:39:21AM

Just noticed that this command doesn't work if you are using the latest version of iTerm (either in OSX or ssh'ed to an Ubuntu box).



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: Hal Itosis on Jan 27, '12 10:44:48AM
@arcticmac:
I couldn't resist trying the rest of them to see if there were any other gems I didn't know about.
Here's a shorter method...
$ stty -e
speed 9600 baud; 24 rows; 106 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
	-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
	-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
	-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
	-dtrflow -mdmbuf
discard dsusp   eof     eol     eol2    erase   intr    kill    lnext   
^O      ^Y      ^D                      ^?      ^C      ^U      ^V      
min     quit    reprint start   status  stop    susp    time    werase  
1       ^\      ^R      ^Q      ^T      ^S      ^Z      0       ^W 

...and there we can see ^T at the bottom (status), which essentially sends a kill -29 signal (SIGINFO) to the current running process.

-HI-

[edited simply to fix spacing in the stty output.]
Edited on Jan 27, '12 10:52:34AM by Hal Itosis


[ Reply to This | # ]
Yup...
Authored by: slb on Jan 27, '12 12:00:31PM

Started verify/repair permissions on disk2 Macintosh HD
[ \ 0%................................................... ] load: 0.59 cmd: diskutil 7625 waiting 0.01u 0.01s
[ \ 0%................................................... ]



[ Reply to This | # ]
Duplicate
Authored by: lincd0 on Jan 27, '12 04:11:01PM

This same hint, which is not at all Mac specific, was published here in 2005:

http://hints.macworld.com/article.php?story=20050520120407161



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: trainiac on Jan 28, '12 02:10:45PM

Strangely, I tried Command-T and it creates tabbed sessions in Terminal. That's a new one on me!



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: slb on Jan 30, '12 01:14:12PM

Not new, and the hint states "CONTROL-T".



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: usovalx on Jan 29, '12 06:26:24PM

It gets even better. Some programs (dd, tar) actually intercept signal sent by ^T and print some extra information.

Try running something like
> tar -cf /dev/null /
or
> dd if=/dev/zero of=/dev/null
and then press Ctlr-T. To stop program press Ctlr-C.



[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: Hal Itosis on Jan 30, '12 02:53:57PM
@usovalx:
Some programs (dd, tar) actually intercept signal sent by ^T and print some extra information.

We can do likewise within our own shell scripts, by simply trapping the signal and adding some code... such as:
ShowInfo ()
{
	# say (or do) whatever "INFO" means to your script
	printf '%s: hello world.\n' "$(basename "$0")"
}

#

trap -- 'ShowInfo >&2'	INFO

-HI-


[ Reply to This | # ]
Control+T in Terminal shows time snapshot
Authored by: MacUser06 on Apr 25, '13 11:11:54PM
There was just no way I could manage to make this work in Snow Leopard, I suspect the Readline library which I love to be the culprit. I added a trap for the SIGINFO signal and a keybinding that triggers the signal in .bashrc to retain the functionality. Feel free to customize the ps command to suit your needs.

 trap 'tty;ps -T -o pid,ppid,pgid,sess,utime,time,pagein,sig,sigmask,nice,nvcsw,nivcsw,command |grep -v "ps -T"' SIGINFO

 bind '"\C-t": "kill -SIGINFO $$\n"'


[ Reply to This | # ]