31

I am running Ubuntu 14.04 (64 bit). When I first found out about the command xterm, I tried the command xterm xterm, and it started infinitely opening new xterm windows.
ctrl + C stops it immediately and closes all windows.

But I wanted to see how far it goes and let it run as long as it can. It ate up almost all the RAM and eventually got closed (I think by the system itself).

So just out of curiosity, why/how does this happen?

3
  • 3
    Off-topic: it was closed because it probably used too much memory and got killed by the OOM (out-of-memory) killer.
    – Léo Lam
    Jun 27, 2014 at 15:09
  • 5
    This should be fixed by version 301: "only set SHELL environment variable to programs found in /etc/shells (prompted by patch/report by Al Poole)". (The answers explain what's with the SHELL environment variable). Jun 28, 2014 at 18:39
  • @CristianCiupitu - +1 - I just installed version 308 - and instead of opening recurring terminals, it opens a blank one, and a second one with bash (the second presumably being the 'shell' of the first xterm.
    – Wilf
    Jul 2, 2014 at 14:13

2 Answers 2

26

I (guess) this is because the first parameter you give to xterm is the shell to use - xterm bash (or xterm /bin/bash), xterm python etc.

So it runs xterm, tries to start xterm as a shell, which starts another xterm as that ones shell, then another, and another...

You can probably find a bit more on this by running man xterm

9
  • 24
    Yes. The first xterm sets $SHELL to xterm and starts another xterm as its shell. That other xterm uses the command in $SHELL as it's shell thus starting another xterm, ... Jun 27, 2014 at 13:50
  • 6
    This part of the answer isn't clear: "which starts another xterm as that ones shell". Why does that happen? Thanks @FlorianDiesch for explaining that part. Jun 27, 2014 at 17:23
  • @JohnKugelman - the first xterm starts the second xterm as its shell, the second xterm starts the third xterm as its shell, the third starts the fourth as its shell... etc
    – Wilf
    Jun 27, 2014 at 18:48
  • 3
    I get why the first xterm starts the second xterm: it's because you typed xterm xterm. But why does the second xterm start the third xterm? You didn't type xterm xterm xterm, so it's not obvious why the third xterm starts. Florian's comment explains why. Jun 27, 2014 at 19:02
  • 1
    So just out of curiosity it is also possible with gnome-terminal ?
    – TuKsn
    Jun 28, 2014 at 13:05
16

Short version: xterm's argument is the shell to execute by xterm; shell is set in environment var, so further calls do a 10 PRINT "xterm" 20 GOTO 10 recursion.

Long version:

  1. xterm xterm passes xterm to xterm call as xterm's shell by setting $SHELL variable to xterm (1st parameter of xterm is interpreted as shell to execute)
  2. then, xterm executed by your xterm xterm command executes the $SHELL - in this case, creating another xterm instance (because $SHELL=xterm now)
  3. $SHELL=xterm already, so the newly created xterm executes xterm
  4. goto 3

Further reading: man xterm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .