LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-03-2013, 08:16 PM   #1
ulkoma
Member
 
Registered: Feb 2012
Distribution: CentOS
Posts: 69

Rep: Reputation: Disabled
Why do I still see the terminal window?


Hi

I am using Ubuntu , when I go to the terminal and type "exec Firefox" Firefox starts but the terminal window is still there till I close Firefox then it disappears
Is not "exec" suppose to kill bash first then starts Firefox?

Thanks
 
Old 05-03-2013, 08:45 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,142
Blog Entries: 2

Rep: Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846Reputation: 4846
Even if exec kills Bash the terminal Window is not killed because it is not Bash. I don't know what Unity uses, but I assume that it is gnome-terminal, which runs Bash in the window.
 
1 members found this post helpful.
Old 05-03-2013, 08:52 PM   #3
ulkoma
Member
 
Registered: Feb 2012
Distribution: CentOS
Posts: 69

Original Poster
Rep: Reputation: Disabled
But why does gnome-terminal disappear after I close Firefox ? Can't it stay with no bash running inside it?
Also how can I watch all these processes calling a killing each other from a higher level? Like can I open an other terminal and watch them using a command or something ?
 
Old 05-03-2013, 09:29 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,707

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
Gnome terminal is an application that handles the window. It spawns a subprocess (a shell) that it uses to interpret the keyboard/mouse events translated and fed to the subprocess, and displays the output of the subprocess.

The subprocess is usually a bash command interpreter. When you "exec firefox" you are directing the suprocess to "chain" to the firefox executable. At this point, the bash interpreter is replaced by the firefox web browser. Note - just because firefox is now running, the gnome terminal is still attached to because firefox is now the subprocess.

When firefix closes (cleans up and exits), that termination is detected by gnome shell. Termination of the subprocess is used to tell gnome terminal to exit... so the gnome terminal windows get closed, and the process exits.

You can "watch" the active processes - one way is to open a gnome terminal and run the "top" program. This program cycles through the process table, sorts it and puts those with the highest CPU at the top. However - it is not guaranteed to catch everything - top only cycles once per second, so very short lived commands (such as "ls") can be missed.

Last edited by jpollard; 05-03-2013 at 09:32 PM.
 
1 members found this post helpful.
Old 05-04-2013, 01:08 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
You can directly start Firefox using:
Code:
~$ firefox &
So when you will close the Firefox, the gnome terminal will not be closed.
 
Old 05-04-2013, 01:30 AM   #6
redfox2807
Member
 
Registered: Jul 2012
Distribution: Debian testing/stable, Sailfish OS, Android
Posts: 131

Rep: Reputation: 20
May I ask a question why you run terminal at all if you want it to be closed then? Alt+F2 firefox should do the same without even opening a terminal.
 
Old 05-04-2013, 03:27 AM   #7
ulkoma
Member
 
Registered: Feb 2012
Distribution: CentOS
Posts: 69

Original Poster
Rep: Reputation: Disabled
Thank you very for your answers guys
Can you kindly explain this paragraph to me:

"Historically, exec was often used to execute the last command of a shell script. This would kill the shell slightly earlier; otherwise, the shell would wait until the last command was finished. This practice saved a process and some memory."
 
Old 05-04-2013, 04:34 AM   #8
redfox2807
Member
 
Registered: Jul 2012
Distribution: Debian testing/stable, Sailfish OS, Android
Posts: 131

Rep: Reputation: 20
if the only purpose of using exec is saving some memory then forget about it. Nowadays memory ain't a problem. Even if it is bash ain't the most memory consuming process
 
Old 05-04-2013, 05:54 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,707

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
Well, to be fair, in most places using exec is faster (no need to allocate a new process), and when cleaning up processes (logout), using exec is/can be much faster.
 
Old 05-04-2013, 05:59 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
A shell script process waiting for the last program it ran to finish before exiting uses few resources but when there is no benefit why not use exec command instead of command? One less process helps when investigating a problem that means examining the processes. In the end, it's mostly about keeping things tidy.
 
Old 05-04-2013, 02:23 PM   #11
ulkoma
Member
 
Registered: Feb 2012
Distribution: CentOS
Posts: 69

Original Poster
Rep: Reputation: Disabled
Thank you again
Excuse my stupidity but what does this mean:

The exec command in Linux
The most common usage of command is the replacement of login shell when the shell in /etc/passwd is not that you want and you have no power to change the setting:
 
Old 05-04-2013, 02:52 PM   #12
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,707

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
Quote:
Originally Posted by ulkoma View Post
Thank you again
Excuse my stupidity but what does this mean:

The exec command in Linux
The most common usage of command is the replacement of login shell when the shell in /etc/passwd is not that you want and you have no power to change the setting:
I believe you have it backward. login (after the series of failed attempts) just exits, causing init to restart the agetty to reinitialize the terminal. The exec system call is used to start the users shell only when the validation succeeds.

Note the difference - the system call doesn't have the same context that the shell has for the exec command. The two pass totally different environments to the new executable. Login sets up the minimal environment to start the shell, and passes a specific name for the shell (it starts with a "-" for interactive shells - a bash shell therefore gets "-bash").

In the exec system call (actually, it is execve), the first parameter is the path to the executable, the second is the array of parameters to be used for the application/process (parameter 0 of argument list as seen by the process becomes the process name), and the rest of the parameters.

In the bash exec command however, the path to the executable is also used for the name of the process... (you have to use the -a option to change that), and there are other options to use various libc functions that interface with the execve system call in different ways (-c and -l).
 
1 members found this post helpful.
Old 05-07-2013, 11:03 PM   #13
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by ulkoma View Post
Thank you again
Excuse my stupidity but what does this mean:

The exec command in Linux
The most common usage of command is the replacement of login shell when the shell in /etc/passwd is not that you want and you have no power to change the setting:
In case your login shell in /etc/passwd is csh and you can't change it, you could login and, at the csh prompt, run exec bash --login to replace csh with bash.

The most common? Not compared to the sequence jpollard explained or to the X equivalent. Maybe the most common usage directly by an interactive user. Never done it myself.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I resize the terminal window from the command line in the gnome terminal QuIcKSpArK Linux - Newbie 5 04-21-2012 02:04 PM
Starting new terminal window or tab from existing window remaining as root? homerun Linux - Newbie 1 08-14-2009 11:34 AM
Ubuntu 8.04 Terminal - Can you make the terminal window transparent with a wallpaper? bparkerson04 Linux - Newbie 6 02-17-2009 05:12 PM
Terminal Window Blackmon Linux - Newbie 3 05-20-2008 08:00 PM
Difference between a Shell terminal window and the KDE Linux Console terminal window? bostonantifan Fedora 2 03-25-2007 07:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration