36

When I run PS one of the columns output is TTY. What does this mean? In particular, how does as value of "??" compare with "ttys000"?

I ask because I have a Java program execute sort via ProcessBuilder, and when this program is run via my IDE (IntelliJ) the process takes 5x less than when run as an executable jar outside the IDE.

In each case I run ps when the sort is running and the only difference is the IDE creats a process with a TTY of ?? whereas the jar creates a process with TTY of ttys000.

kgui
  • 4,015
  • 5
  • 41
  • 53
Aaron Silverman
  • 22,070
  • 21
  • 83
  • 103

2 Answers2

41

A TTY is a computer terminal. In the context of ps, it is the terminal that executed a particular command.

The abbreviation stands for "TeleTYpewriter", which were devices that allowed users to connect to early computers.

In relation to your situation, the jar creates a virtual terminal named 'ttys000' but the IDE does not attach to a virtual terminal to execute the command.

George Cummins
  • 28,485
  • 8
  • 71
  • 90
  • Interesting, so how can I have the jar execute unattached to a terminal so I don't get the performance hit? – Aaron Silverman Aug 18 '11 at 20:51
  • You detach a process from the terminal by appending ' &' to the command line. I would be surprised if the performance hit is a result of the command being attached to the terminal, however. I think it is more likely that the IDE is performing some sort of optimization. I will look forward to hearing about your results. – George Cummins Aug 18 '11 at 20:54
  • Even with & it still takes longer and shows up in ps with a TTY of ttys000. However when I execute the jar via a simple java program in the IDE it runs detached and shorter. I wonder what kind of optimization it could be, and/or if the OSX terminal itself is slowing things down. – Aaron Silverman Aug 18 '11 at 21:39
  • You've answered my TTY question (Thanks!) created a new one for the performance issue: http://stackoverflow.com/questions/7124489/sort-command-takes-much-longer-depending-on-where-it-is-executed-fastest-from – Aaron Silverman Aug 19 '11 at 16:18
  • 3
    Note: my performance issue was due to IntelliJ and the shell using different default charsets. – Aaron Silverman Jun 13 '14 at 16:24
  • @GeorgeCummins in most shells & puts a process in the background but does not disassociate the controlling terminal. You need to use "nohup" (man 1) or "disown" (see you shell man page) to do that. zsh users can use "&!" instead of "&". – Jürgen Strobel Aug 23 '18 at 10:59
5

A process can be (and usually is) bound to a "controlling terminal". This terminal may be hardware at the end of a serial line, or much more likely today, be a virtual software equivalent. The TTY is inherited from the parent process. Most likely your IDE disassociates itself from its TTY, and when started outside your java program inherits your shell's TTY.

jameshfisher
  • 34,029
  • 31
  • 121
  • 167
Jürgen Strobel
  • 2,200
  • 18
  • 30