Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Eotvos Lorand University 
Tools of Software Development 
Johnnatan Messias 
Alison Miranda 
Ernane Aguiar 
Andrey Khasanov
Contents 
1 Introduction 1 
1.1 The Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 
1.1.1 The Lan...
1 Introduction 
This paper aims to make students become familiar with the UNIX environment, 
developing programming skills...
PWD: it displays the current directory seen by the process. 
 WAIT: it makes the shell waiting for the end of all processe...
char s p l i t ( char l i n e , char vSt r ing , char command , int  l eng th ) { 
char tok = NULL; 
int i ; 
tok = ( char...
MyShell - English
MyShell - English
MyShell - English
MyShell - English
MyShell - English
MyShell - English
MyShell - English
MyShell - English
MyShell - English
MyShell - English
MyShell - English
Upcoming SlideShare
Loading in …5
×

MyShell - English

217 views

Published on

This paper aims to make students become familiar with the UNIX environment, developing programming skills in C, to increase their exposure to a shell functionality and put into practice concepts of management processes.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

MyShell - English

  1. 1. Eotvos Lorand University Tools of Software Development Johnnatan Messias Alison Miranda Ernane Aguiar Andrey Khasanov
  2. 2. Contents 1 Introduction 1 1.1 The Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1.1 The Language of MyShell . . . . . . . . . . . . . . . . . . . . 1 2 The implementation of MyShell 2 2.1 Handling the Data Entry . . . . . . . . . . . . . . . . . . . . . . . . . 2 2.2 Function for Ls command . . . . . . . . . . . . . . . . . . . . . . . . 3 2.3 Function for Pwd command . . . . . . . . . . . . . . . . . . . . . . . 3 2.4 Function for Cd command . . . . . . . . . . . . . . . . . . . . . . . . 4 2.5 Function for Cat command . . . . . . . . . . . . . . . . . . . . . . . . 4 2.6 Function for Grep command . . . . . . . . . . . . . . . . . . . . . . . 5 2.7 Function for Ping command . . . . . . . . . . . . . . . . . . . . . . . 5 2.8 Function for Kill command . . . . . . . . . . . . . . . . . . . . . . . . 5 2.9 Function for Date command . . . . . . . . . . . . . . . . . . . . . . . 6 2.10 Function for Mkdir command . . . . . . . . . . . . . . . . . . . . . . 6 2.11 Function for Mv, Rm and RmDir commands . . . . . . . . . . . . . . 7 2.12 Function for Cp command . . . . . . . . . . . . . . . . . . . . . . . . 8 2.13 Function for Chmod command . . . . . . . . . . . . . . . . . . . . . . 8 2.14 Function for Ps command . . . . . . . . . . . . . . . . . . . . . . . . 9 2.15 Function for Sh and Bash commands . . . . . . . . . . . . . . . . . . 9 2.16 Function for Sleep command . . . . . . . . . . . . . . . . . . . . . . . 10 2.17 Function for Pipe and Background commands . . . . . . . . . . . . . 10 2.18 Function for Exit command . . . . . . . . . . . . . . . . . . . . . . . 10 2.19 Main Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 List of Programs 1 Function split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Function ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 Function pwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 4 Function cd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 5 Function cat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 6 Function grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 7 Function ping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 8 Function kill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 9 Function date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 10 Function mkdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 11 Function Rm, Mv and RmDir . . . . . . . . . . . . . . . . . . . . . . 7 12 Function cp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 13 Function chmod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 14 Function ps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 15 Functions Sh and Bash . . . . . . . . . . . . . . . . . . . . . . . . . . 9 16 Function sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 17 Function Pipe (|) and Background (&) . . . . . . . . . . . . . . . . . 10 18 Function Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 19 Function Main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2
  3. 3. 1 Introduction This paper aims to make students become familiar with the UNIX environment, developing programming skills in C, to increase their exposure to a shell functionality and put into practice concepts of management processes. 1.1 The Problem Implement a minimum shell, the MyShell to put into practice the principles of handling processes. This kind of knowledge is essential in the development of complex systems with many processes, such as servers. 1.1.1 The Language of MyShell The language understood by MyShell is quite simple. Each different sequence of space characters is considered a term . Terms may be internal operations of the shell, names of programs that should be run, arguments to be passed to the commands or programs and special operators. Internal operations of the shell are the strings cd; pwd;wait and exit. These operations must always end with a signal for the end of the line (return) and must be entered immediately following the prompt (ie, must always be entered as separate lines of any other commands). The operators are the symbols & (background) and k (pipe), when they occur alone (as a single character between spaces). Running programs are identified by the name of its executable file and may be followed by a maximum ten arguments (parameters to be passed to the program through the vector argv[]. Each trigger command must end with one of the operators, or with the end of line. End of Line: indicates that the process should be launched and the MyShell must wait at their end before displaying another prompt. Background: the process should be launched and MyShell should continue its execution. It could mean the continuation of the interpretation of the command line, if there are other commands on the line, or the immediate return to the prompt. Each time a process is triggered in the background, MyShell should display a message in this regard, with the handle (pid) of the process in question. Pipe: the content after the operator another command to be executed should be interpreted, and the standard output of the first process must be connected to the standard input of the next process. To simplify the implementation, MyShell does not allow chaining pipes, ie, is not allowed to put another pipe the output of the second program. You can, however, put both programs in background, finishing the sequence with the appropriate operator (in this case, a message about the operation in the background should be displayed for each process). The internal commands have the following interpretations: CD: it changes the current directory of the shell. This will impact on the visible files. 1
  4. 4. PWD: it displays the current directory seen by the process. WAIT: it makes the shell waiting for the end of all processes that may still be running before displaying a new prompt. Each process that is found during the waiting must be informed by a message on the command line. If there is no process by which to expect, a message about should be displayed and MyShell should continue its execution. EXIT: it terminates all the operation of the shell if there is no processes in background. Otherwise, it displays a message saying the fact and performs the operation wait before terminating. 2 The implementation of MyShell Later we will present the implementation of functions that treats a particular command that will be entered by the user in MyShell, some of the primitive func-tions that will be used in other functions are explained below: Primitive fork(): it is the only system call that enables the creation of a process in UNIX. Primitive execv(): it is a function, whose first argument is the full path to the executable or script to be executed and the second is the name of the program to be executed. Primitive wait(): it suspends the execution of the father process until the death of his child process (if the child is already dead, the function returns -1 immediately). Primitive exit(): it terminates the execution of MyShell only if there are no processes in background. Some libraries in C that were used for the implementation of the program: errno:h signal:h sys=types:h sys=wait:h unistd:h 2.1 Handling the Data Entry The function split handles the input of user data in MyShell using auxiliary functions of the library string:h defined in the language. 1 2
  5. 5. char s p l i t ( char l i n e , char vSt r ing , char command , int l eng th ) { char tok = NULL; int i ; tok = ( char ) mal loc ( s izeof ( char ) 200) ; 5 s t r cpy ( tok , l i n e ) ; tok = s t r t o k ( tok , n ) ; command = s t r t o k ( tok , ) ; //0 th p o s i t i o n i s used on the e x e c v 10 vSt r ing [ 1 ] = s t r t o k (NULL, ) ; i f ( ! vSt r ing [ 0 ] ) vSt r ing [ 0 ] = ; 15 for ( i = 2 ; vSt r ing [ i

×