Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am running one bash terminal in linux mint. I wanted to see the process ids of running terminal.

So I tried two things:

ps -C 'bash'

ls -l /proc/*/exe | grep bash

Both of this giving two process ids. Can any one explain reason for these two process ids for only one terminal? how to identify the real process id of terminal between two?

Thanks

share|improve this question
2  
Note that bash is a shell – a command interpreter – not a terminal. Its parent, the program that draws bash's output on screen, would be the terminal. In bash, the special variables $$ and $PPID expand to PIDs of the shell itself and its parent. –  grawity Mar 1 at 19:06

1 Answer 1

up vote 2 down vote accepted

Terminals do not have process IDs.

It is processes that have process IDs, of course. Terminals have IDs of their own, and you'll see them in the outputs of tools like w, who, and (in the TTY column) ps. But these are not process IDs.

The relationship between processes and terminals is not 1:1. Moreover, as grawity pointed out, a shell is not a terminal. A terminal is a device. A shell is a program. The bash program is a shell, whose input and output (in interactive mode at least) are read from and written to a terminal device.

Terminals on personal computer Linuxes and Unices are generally not real, physical, devices, plugged into a serial port of some sort. Rather, they are either virtual terminals or pseudo terminals. Both are the products of terminal emulator programs.

  • In the case of virtual terminals, that program is embedded into the operating system kernel (albeit that there have been moves to change this) and it doesn't have a process ID because it isn't a distinct process in its own right.
  • In the case of pseudo-terminals there's a process that manages the "master" side of the device, and displays the contents of the terminal in some fashion. Usually it is a GUI program, such as xterm, lxterminal, konsole, gnome-terminal, or rxvt. (It could, alternatively, be the SSH or TELNET daemons.) Those do have process IDs. But it is the terminal emulator that is the process, not the pseudo-terminal device.

As to why you see two bash processes: You have two bash processes running. It's that simple. They aren't necessarily associated with the same terminal device, or even with any terminal device. Again, the TTY column in the output of ps will tell you what controlling terminal each process has. (Terminals don't have process IDs, but in a way processes have terminal IDs.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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