I used the script
command immediately after I started the terminal, it started recording my current session but when i used ps
command after that it is showing only two processes, one for bash
and one for ps
itself but it is not showing any process for the script command that is running in the background, why is it so? Speaking in a more general way actually I have never seen the ps
command showing more than 2 processes on my terminal, is there something wrong with my shell or terminal settings? I am currently using Ubuntu.
1 Answer
There is nothing wrong with your terminal or your shell. By default, ps
shows processes with the same effective user identifier as the user running it, and associated with the same terminal. This typically results in only two processes showing up: the current shell, and ps
itself. If there are any background processes associated with the current terminal, they will show up too; you can see this by running
sleep 120 &
ps
To see all processes, run
ps -e
There are a number of other process selection flags, see man ps
on your system for details.
When you run script
, it allocates a new terminal and starts a new shell; so ps
inside script
is running on a different terminal (even though it’s in the same terminal window on your system, or on the same virtual console). That’s why you don’t see script
. You can see this happen by running tty
before and after running script
: you’ll see it output two different values.
See also What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?