Miscellaneous
  Home arrow Miscellaneous arrow Page 4 - The Shell and UNIX
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

The Shell and UNIX
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-04-08

    Table of Contents:
  • The Shell and UNIX
  • Shell Programs
  • Shell Commands
  • Command execution

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Shell and UNIX - Command execution


    (Page 4 of 4 )

     

    So how does a command's execution happen? In the case of built-in commands, this will be done by the running shell. If the tool/command is inside an external binary file, then something else happens. The current shell we are just using inside the terminal will start a new shell. This will get the content of the command line as input. 

    While the child shell completes its command, the father shell will wait. Therefore, we will not have the prompter string. The child shell will inherit the input/output files and the environment variables. While a running shell starts, the operating system will store some important data related to this. All of this is stored inside what we call the process. The shell itself is a process. 

    On the command line, there are two kind of separating characters: the new line and the ;. On a single command line we can write more commands separated with the ; , however these will be executed one after another and not at the same time. 

    The command we start we describe as running in the foreground, as it will not give back the prompter and will print on the current shell terminal. We can also run the process/command in the background. If this is the case, the shell will give back the prompter and allow us to start multiple commands running at the same time. 

    There are two ways to achieve this. The first is to add to the end of the command line the & character. For instance, the sleep command will force the terminal to wait the given number of seconds if started in the foreground. Nevertheless, if we add to the end of the command the & character, the child shell will still wait for the given seconds; but during that we can make further commands, as we will have the prompter. 

    sleep 2 &;

    The second option is to start the command line as usual, and suspend it with the Ctrl + Z key combination. With the help of the bg command, we can now start this in the background. You can bring back to the foreground a background process with the help of the fg command.  

    UNIX systems assign to every process an integer number to make it easy to work with them. When we send to the background or bring to the foreground a command line, this is what we will get back. We can use this to choose which of the commands to bring to the foreground if we have multiple commands in the background. Here is example from the terminal: 

    Naturally, the commands can work for your own shell scripts, not just the ones already existing in the shell. While an echo may run fast enough so you should not worry about running it in the background, a more complicated script can have run times well beyond the insensible one-second boundary. 

    There is a lot more to know about the processes and tasks, however we will work with this later. For now, this will be enough for you to understand the general concepts of how a command works on the shell. 

    This is all for today. In the hope that you enjoyed and learned a lot from this article, I invite you to come back next week when we will observe the shell variables, the quotes, language packs, how to customize your shell to start as you wish and other interesting subjects about the shell. I would like also to ask you to rate my article and if you have any kind of question just ask it in the blog that you will find at the end. Live With Passion! 


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    MISCELLANEOUS ARTICLES

    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek