16

When I try to close a tab in Gnome Terminal, it says:

Close this terminal? There is still a process running in this terminal. Closing the terminal will kill it.

How can I find out what is still running? Note that there is nothing in the output of jobs. Thanks.

Tim
  • 24,657
  • 62
  • 151
  • 245
  • 1
    If you're at the shell prompt while this message is shown, probably this is a nested shell (not the one directly started by the terminal emulator). Maybe you've started a `screen`, `tmux`, `script`, `ssh`, `mc` and turned the panels off, or just another shell by e.g. typing `bash`, or something along these lines. Press Ctrl+D or type `exit` to quit your shell, you'll see where you end up. – egmont May 14 '16 at 14:54
  • Thanks. after `exit`, the gnome terminal tab doesn't close. – Tim May 14 '16 at 14:59
  • 1
    A second `exit`will probably close it then. @egmont can you move this to an answer please. – Videonauth May 14 '16 at 15:08

4 Answers4

15
ps T

Selects all processes associated with the terminal.

tmcp
  • 329
  • 3
  • 4
3

If you started some process in terminal (eg. gedit) than the Process ID (PID) (of bash) and Parent Process ID (PPID) (of gedit) for this two processes will be the same. This can be seen in the output of

ps -ef

command. To make it more readable lets first "pipe" the output to grep to find the PID of all "bash" processes currently running and than "pipe" it again to awk. The awk selects only the PID and process name fields (field 2 and 8) and outputs it to the screen.

ps -ef | grep bash | awk '{print $2 ": " $8}'

The number in the output is PID. You will use it to find what process was started in terminal that has that PID. Note that there can be more than one line of output if you have more than one terminal opened. Now to find the "child" processes (if any) of that terminal-sessions we can use this command:

ps -ef | awk '{if ($3 == EnterPID) print $2 ": " $8;}'

You must enter the PID number in place of EnterPID in the last command. If there is more than one PID for "bash" you must try them all.

The last command just looks the output of ps -ef and searches if PID (that you have found from previous command) and PPID are the same for any process.

More info:

man ps

man awk

NonStandardModel
  • 3,350
  • 7
  • 27
  • 45
2

You can take a peak at the processes who list your shell's PID as parent. As you may or may not know , we can specify ps format

SHELLPID=$$ ; ps -e  -o cmd,pid,ppid | awk -v shell=$SHELLPID  '$NF~shell'   

Here, we get the shell's PID from special variable $$ into SHELLPID , which then can be used by awk in pipe's subshell. Essentially we're just listing processes in form NAME,PID,Parent PID , and filter out only those who have the appropriate PID in the last column.

Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492
-1

You can use htop. In Ubuntu 16.04 ( and higher), you can install it just by typing sudo apt-get install htop.

You can also use top .

Rangerix
  • 451
  • 2
  • 6
  • 11