I creart the first terminal , then I use "sleep 1000 &" and I found it by "ps". The problem is when I creat the second terminal and put "ps" ,there is no sleep process. I want to know why ?

enter image description here(my homework say "hint: TTY column" )

  • Hint: What else is not displayed in the output. – ctrl-alt-delor Apr 1 at 6:53
  • You mean beceuse the tty column I cannt see other output like the "sleep" ? – Tasuo Apr 1 at 6:57
  • Unclear. Did you start a second sleep in the second terminal? Or are you expecting pts/2 to tell you what is going on in pts/1? If you run ps in both terminals, you will find the PIDs for both bash and ps are different in pts/1 and pts/2. – Paul_Pedant Apr 1 at 8:49
  • Just one sleep.It in the first terminal. I mean I creat two terminals. – Tasuo Apr 1 at 11:06
  • I want to konw if there are someting connections between the 【phenomenon】and the tty column – Tasuo Apr 1 at 11:09

By default, ps only shows processes attached to the current terminal (tty): in your case, your shell and ps itself (both on pts/2). You need to lift this restriction to see sleep; for example

ps -e

See man ps for the many options available to filter processes.

| improve this answer | |
  • I use ps auxw since old habits from SunOS3 – Basile Starynkevitch Apr 1 at 6:37
  • yes, I found the sleep. – Tasuo Apr 1 at 6:43
  • Thanks and one more question . So what the correlation it have with 【tty column】? – Tasuo Apr 1 at 6:46
  • Read first line of answer. – ctrl-alt-delor Apr 1 at 6:54
  • A “tty” is a terminal: ps only shows processes on the same terminal, i.e. with the same value in the TTY column. With ps -e you’ll see many different values, including “?” (no terminal). – Stephen Kitt Apr 1 at 6:55

The problem is when I create the second terminal and put "ps" ,there is no sleep process.

With some (not all) interactive shells, the sleep could be a shell builtin invoking e.g. sleep(3) (exactly as cd is a shell builtin invoking chdir(2)).

When that is the case, you won't see any sleep process because there is none. The process which is then sleep(3)-ing is your Unix shell; you could even write your own shell interpreter (look into sash for an easy but a little bit buggy example).

Many Linux shells are open source software (or free software), so please study their source code to find out if they do call sleep(3) or usleep(3) -or even appropriately poll(2), etc ...- See also time(7) and select_tut(2). Read more about syscalls(2) and think of those done by your shell (or observe them with strace(1) or ltrace(1) or a debugger) .

Many Linux distributions have GNU bash as the usual interactive shell. But you could install zsh or fish or es as your login shell (with chsh(1)).

My personal preference is zsh (whose autocompletion facilities on Debian are outstanding).

Consider reading some textbook about Operating Systems and/or coding your own Unix shell as an exercise, or extending some existing one (e.g. by adding a sleep builtin, if it does not have one).

| improve this answer | |
  • I dont konw if it doesnt exist,why I see it in the first terminal by "ps"? – Tasuo Apr 1 at 6:28
  • Did you downloaded and studied the source code of your shell? Did you code your own Unix shell? – Basile Starynkevitch Apr 1 at 6:29
  • @Basile, ps in the first terminal lists sleep, so it’s not a shell built-in... – Stephen Kitt Apr 1 at 6:37
  • On sash it is one. I tend to believe that on zsh also – Basile Starynkevitch Apr 1 at 6:38
  • 1
    There’s even a list of sash built-ins in the Wikipedia article you linked to. – Stephen Kitt Apr 1 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.