Home > Enterprise >  How to get and output a pid of a 2nd terminal tab on 1st terminal tab?
How to get and output a pid of a 2nd terminal tab on 1st terminal tab?

Time:12-07

The question is related on a Linux Mint 64, 20.x system with Cinnamon desktop

Running the follow sample code on terminal are doing the follow:

  • output the pid of 1st terminal tab on 1st terminal tab
  • create a 2nd terminal tabs
  • output one thing on 2nd terminal tab

Sample code:

echo "pid von TAB1: $$"; gnome-terminal --title="Titel of 2nd TAB" --tab --active -- bash -c "sensors; read exec bash"

Booth terminal tabs have a own pid. This can be seen by:

ps ax | grep bash

Booth terminal tabs can be closed for testing purposes by his own pid by:

kill 123456

How to get and output a pid of a 2nd terminal tab on 1st terminal tab ?

CodePudding user response:

Partial solution which doing the follow:

  • Output on first terminal tab, all bash related pids before opening 2nd terminal tab
  • Output of the true pid from first terminal tab on first terminal tab
  • Output of the true pid from second terminal tab on second terminal tab
  • Output on first terminal tab, all bash related pids, after opening 2nd terminal tab
prep bash; echo "pid von TAB1: $$"; gnome-terminal --title="Titel of 2nd TAB" --tab --active -- bash -c 'echo $$ & sensors; read exec bash'; pgrep bash

The following are not solved by this partial solution:

  • Unable to output the pid of second terminal tab on first terminal tab.

CodePudding user response:

Partial solution which doing the follow:

  • output on first bash tab a list of bash related pids before opening 2nd bash tab
  • output on first bash tab a list of bash related pids after opening 2nd bash tab

echo list of bash tabs before open 2nd tab; pgrep bash; gnome-terminal --title="Titel of 2nd TAB" --tab --active -- bash -c "sensors; read exec bash"; echo list of bash tabs incl. 2nd bash tab; pgrep bash

The following are not solved by this partial solution:

  • how to get as a output, the pid which are on 2nd pid output, a not on first pid output
  • Related