Ubuntu: How to find still running processes in a terminal?


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.


ps T  

Selects all processes associated with the terminal.


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »