Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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?
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 ?
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.
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."
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.
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).