2

I started Chrome and Firefox from search bar and have found they were also opened from a terminal

$ pstree -aps 5221 | head -10
systemd,1 splash
  `-gdm3,1027
      `-gdm-session-wor,2418
          `-gdm-x-session,2529 --run-script env GNOME_SHELL_SESSION_MODE=ubuntu /usr/bin/gnome-session --session=ubuntu
              `-gnome-session-b,2545 --session=ubuntu
                  `-gnome-shell,2741
                      `-chrome,5221    
                          |-cat,5227
                          |-cat,5228
                          |-chrome,5232

Chrome was invoked from a GUI utility called gnome-shell.

Does any installed software have to run from a form of terminal?

Additionally, I have found the terminal I am working from is not named tty but

$ tty
/dev/pts/0

and can't communicate with tty2

$ echo "very strange long text" > /dev/tty2
$ grep -r  'very strange long text' /   2>/dev/null 

However, grep does not return the sent message. The text to tty2 is lost.

2
  • 1
    For future, please remember to separate questions, unless they're closely related. You have 3 question in one post: asking about /usr/bin and /bin, asking about pts , and communicating with tty2. However, in this case they are related from what I see, as you have confusion as to how shell relates to tty device Jan 19, 2019 at 9:12
  • 2
    Always glad to help :) Jan 19, 2019 at 9:23

1 Answer 1

3

Do processes need a terminal ?

There are several things that you need to understand in order to answer this question:

  • /usr/bin and /bin contain executable files
  • A shell is an interface to the user - it executes commands or performs functions that user wants; it is like levers and switches on a machine - you pull lever, and machine does something
  • GNOME shell is GUI shell, bash is text-based shell. They are also processes, and can start new ones via fork() and exec() calls.

Does any installed software have to run from a form of terminal?

No, not really. The very first process on the system, /sbin/init with PID 1 ( and that's systemd in your case), has no associated controlling terminal. In fact, a daemon process does not have a controlling terminal. All processes on Linux are started via two syscalls - fork() and exec() - where you first create a "copy" of the original process, and then via exec() you run an executable, an applications in /bin and /usr/bin, or any other location you specify. Daemons can do exactly the same thing.

So in theory, I could make a daemon process that has no controlling terminal - no tty - and yet I could use fork() and then exec() to run something from /usr/bin. Of course, the command which I call has to be OK with that - some commands require having a controlling TTY in order to work.

In this question, it seems the big confusion is that shell is the same as tty, however they're different - tty designates a device (real or virtual), while shell - it's a process that interfaces with the user and the system to perform certain functions/actions.


Shell vs tty

Notice that the process name is -gnome-shell,2741. Gnome Shell is GUI shell, it is very different from typical text-based command interpreter such as bash or ksh. You can start applications, files, windows, though you interact with it via shortcuts and mouse much more than with text-based shell.

The TTY you use /dev/pts/0 and /dev/tty2 are two different things entirely. Generally /dev/ttyXX indicates a console driver, and /dev/tty2 is a device file which is also associated with special TTY driver. /dev/tty[1-xx] usually denote virtual consoles, which can be accessed via Ctrl+Alt+F1-7. By default there are tty1 to tty7 open, with GUI on Ubuntu defaulting to tty7. On other distributions GUI may be on different tty, for instance if I recall correctly in Fedora it was tty1. Of course, there are ways to open more than 7 virtual consoles. See Why so many virtual consoles?

Every open tab and every new window of the terminal window you use within graphical shell - that will have /dev/pts/x file associated. pts part stands for "pseudoterminal". These are involved with consoles that are implemented via software and don't represent real hardware, e.g. when you use terminal emulator or SSH connection.

It's also important to note that shells such as bash are not tty, the /dev/tty2 is a device which has driver associated behind it. /bin/bash is an executable file, and is executed as command itself. While there are processes in kernel that manage /dev/tty2 it is not a process; by contrast /bin/bash is a process that you can start. And this is in fact what happens when you open a terminal - your terminal window starts /bin/bash as process.

And of course, you can write to /dev/tty2 or /dev/pts/0 , if you have permission. For example, in order to use /dev/ttyUSB0 or /dev/ttyACM0 to write to Arduino or another embedded system, you have to belong to dialout group, which owns these special devices. These two devices emulate serial console, so you can send data to the connected devices or program it. In case of special hardware devices like that, you also have to consider the speed or baud rate at which these devices read and send data.

See also

You must log in to answer this question.

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