S E C T I O N O V E R V I E W

Size: px
Start display at page:

Download "S E C T I O N O V E R V I E W"

Transcription

1 INPUT, OUTPUT REDIRECTION, PIPING AND PROCESS CONTROL S E C T I O N O V E R V I E W In this section, we will learn about: input redirection; output redirection; piping; process control; 5.1 INPUT AND OUTPUT REDIRECTION The shell can be considered as a medium that interfaces end-users and the UNIX operating system kernel. Typically, when someone enters a string in a terminal window, the sequence of characters enters is buffered. This means that characters entered are not sent straight away into the shell. Instead, they are stored somewhere temporarily, typically in a place called buffer. Any data held there are usually transmitted when user presses the <Return> key. This is obvious as we have used several UNIX commands so far. For instance, by typing ls the shell does not react. It simply buffers the characters entered in a sequential order. Then by pressing the <Return> key, this sequence is transmitted into the shell for further processing. The sequence of characters entered for transmission is called input. The processing of input by the shell usually results in the production of data that are displayed on our terminal. This is known as output. Considering again the ls command, the corresponding output should be a list of all files that reside in our current directory. At this point, readers should be able to realise that each UNIX command is associated with two streams, namely the input and the output stream. However, there is also a third one known as error output. Moreover, as PAGE 1

2 these are the standards ones, their names are known as standard input, standard output and standard error. They are abbreviated as stdin, stdout and stderr with corresponding identifiers 0, 1, 2 respectively. FIGURE 5.1: STDIN, STDOUT AND STDERR As elaborated previously, the role of standard input and standard output is clear. The role of stderr is twofold. The standard output stream allows us to have error messages if something goes wrong with the execution of a command. Whilst it also gives us some indications regarding the type of error. For example, if we attempt to execute the command ls with argument a file name of a file that is does not exist; we will end up with an error message indicating the file is not existent. So far we have seen several means that allows us to display the output of a file on the terminal window. These include the more command or applications such as vi and emacs. At this stage, we will start working with another one known as cat which stands for concatenate. SYNTAX cat cat <filename> <filename> NOTE: IF NO ARGUMENT IS ENTERED IT TAKES ITS INPUT FROM THE STANDARD INPUT STREAM. [CTRL-D TO EXIT IS REQUIRED] SYNTAX 5.1: cat SYNTAX As, its name reflects, the cat command concatenates all files entered as arguments and outputs them on the terminal window using the standard output. PAGE 2

3 EXAMPLE cat 4 tiger% cat file1 file2 This is my first file. This is my second file. 5 tiger% SAMPLE OUTPUT 5.1: CAT EXAMPLE Sometimes, we may need to use commands with some predefined input stored in a file. Some other times, it is essential to store data outputted by a command into a file. This can be achieved with the input (<) and output (>) redirection characters. For instance, we may need to redirect input from a file into a UNIX command and to redirect its output into a file. Some other times, we may need to store the output of a command i.e. who to a file in order to store this data for our archive. These needs generate four possible options. However, there are more as, for example, we may need to redirect output to another device such as a printer. The following subsections describe standard input and output redirection that reflect input from files and keyboards and output into files and the terminal display KEYBOARD INPUT AND FILE OUTPUT REDIRECTION Figure 5.2 illustrates the concept of output redirection into a file called myfile. By executing the command cat > myfile, we are able to enter data using the keyboard input. FIGURE 5.2: FILE OUTPUT REDIRECTION As shown, cat command can also be used without arguments. This means that everything that is entered after its execution is displayed on the terminal display. However, as we instructed the shell to substitute the terminal display with a file through output redirection, everything that is entered is redirected and stored into this file. PAGE 3

4 5.1.2 FILE INPUT REDIRECTION In a similar fashion like file output redirection, the following figure (5.3) illustrates the concept of input redirection. More precisely, users can instruct the shell that input should be taken from a file. FIGURE 5.3: FILE INPUT AND FILE OUTPUT REDIRECTION By entering the command cat < myfile, we instructed the shell to get the contents of the file called myfile and use them as input for the command cat. The execution of this command should display the contents of myfile the terminal display. Note that as cat accepts arguments such as files the input redirection can be omitted FILE INPUT AND FILE OUTPUT REDIRECTION We may also wish to process some data already stored into a file and the output obtained by executing a UNIX command should be stored in a file, as well. Therefore you can use the standard input and output redirection characters associated with the corresponding files. FIGURE 5.4: FILE INPUT REDIRECTION The command cat < myfile > mynewfile indicates the shell to accept as input the contents of the file myfile and based on the input given to the PAGE 4

5 command cat to redirect the command s output into a new file called newfile. Filenames that are given for input and output redirection should be distinct. Alternatively, you cannot redirect input to a command from a file and redirect output of this command to the same file. If you will attempt to do this, you will eventually destroy the source file as the system will attempt to create a new destination file by deleting the source one FILE OUTPUT REDIRECTION The last case corresponds to the file output redirection. Consider, for example, that we need to know who is currently logged in the same UNIX machine. Although we can do this using the who UNIX command, we also need to store this information and process it later. In this case, we can instruct the shell to redirect the contents obtained from the who command into a file given as an argument. FIGURE 5.5: FILE INPUT REDIRECTION The who > myfile redirected standard output into a file called myfile. Users can use the cat or more command to see the contents of this file. Moreover, they can use editors to open myfile file. In fact, the contents of this file are exactly the same as those would be displayed on the terminal window ISOLATING STANDART OUTPUT AND ERROR OUTPUT As elaborated previously, we can also redirect standard output and standard error. Moreover, we can also separate them. This is useful, in case we need to obtain standard output and standard error. Consider for example, we need to find a file in a UNIX directory. Moreover, as we are not aware about the location of this file we wish to start searching from the root directory. The problem in this case is that we can search only directories, we have access rights. If the find command will attempt to access restricted areas, this would result in the generation of error messages indicating that. Therefore, it is PAGE 5

6 reasonable to redirect standard error to a file of even to a device in order to avoid redundant output. This is carried out by typing find / -name myfile print 2> /dev/null. Observe the string 2> that should be entered without spaces. The number 2 corresponds to the standard error while the symbol (>) refers to the output redirection character. Moreover, the string /de/null represents the device null located into the /dev/ directory. This device will simply discard any error messages forwarded to it. In order to simplify that, we can consider some parts of this command as crudely defined if then statements. In short, the 2> means that if there is a standard error message, recalling from back 2 represents stderr, then redirect the standard error into the /dev/null device. Here is an example output that illustrates this concept (5.2). NOTE THAT THIS IS A SPECIFIC SHELL SYNTAX USED BY BOURNE SHELL FAMILY. THEREFORE YOU NEED TO SWITCH TO BOURNE SHELL BY TYPING SH. OBSERVE THAT THE PROMPT HAS BEEN CHANGED TO $. EXAMPLE sh, find 8 tiger% sh $ find / -name mynotes -print find: cannot read dir /lost+found: Permission denied find: cannot read dir /usr/lost+found: Permission denied find: cannot read dir /usr/local/lost+found: Permission denied./one/mynotes./mynotes $ find / -name mynotes -print 2> /dev/null./one/mynotes./mynotes SAMPLE OUTPUT 5.2: ERROR REDIRECTION IN BOURNE SHELL Initially, we attempted to fine mynotes file starting form the root directory. However, the UNIX system started searching; we received numerous errors as permission to certain directories was denied. Therefore, we followed a more efficient approach by redirecting standard error to the /dev/null device. In this way, we just filtered standard error based on its file descriptor and redirected it to the /dev/null device. In a similar fashion, we can redirect standard error and standard output to a file for further processing. However, we have a slightly different syntax PAGE 6

7 for carrying out that. The following is an example base on the C Shell. Note that in order to switch back to the C Shell, we usually use type csh. EXAMPLE csh, find $ csh 1 tiger% find / -name mynotes -print >& myfile 2 tiger% SAMPLE OUTPUT 5.3: STANDARD OUTPUT AND ERROR REDIRECTION The execution of find / -name mynotes print >& myfile redirected standard error and standard output into file myfile. This means that any errors and any results were placed in myfile. We can conclude that these redirections in C Shell are not so flexible like in the Bourne Shell family. For instance, using the C Shell, we may need to obtain only the standard output without the standard error. However, we cannot separate them. A possible solution is that we may to redirect standard output to a file while standard error is redirected to the window terminal. This is shown in sample code 5.4. EXAMPLE find, cat 15 tiger% find / -name mynotes -print > output find: cannot read dir /lost+found: Permission denied find: cannot read dir /usr/lost+found: Permission denied 16 tiger% cat output./one/mynotes./mynotes 17 tiger% SAMPLE OUTPUT 5.4: STANDARD OUTPUT AND ERROR REDIRECTION The find / -name mynotes -print > output filtered standard error by displaying it on the terminal window while standard output was being redirected to the file output. The command cat output displayed the standard output obtained. As there are differences regarding the syntax of the redirection characters among shells; we provide a table with some form of these redirections between the C Shell and Bourne Shell family. C SHELL BOURNE SHELL DESCRIPTION > > Redirect standard output >& Redirect standard output and standard error < < Redirect standard input >! Redirect standard output by overriding existed file >&! Redirect standard output and error by overriding existed file PAGE 7

8 Redirect standard output to another command (pipe) >> >> Append to standard output >>& Append standard output and standard error 2> Redirect standard error 2>&1 Redirect standard error to standard output 2>&1 Pipe standard output and standard error to another command TABLE 5.1: C AND BOURNE SHELL FAMILIES: INPUT/OUTPUT REDIRECTIONS The last redirection output redirection character, we should consider is (>>). Recalling back, the (>) character will redirect standard output to a file with a given filename. However, if the file exists, the shell will override it in order to place any new information. This (>>) character or the sequence of these two characters will instruct the shell to append an already existed file. Therefore, any information obtained by the execution of a command will be inserted at the end of any contents held in the existed destination (file). Note that, if the file does not exist the shell will create a new one. This is illustrated in sample output 5.4. EXAMPLE csh, find 21 tiger% date > events 22 tiger% cat events Sun May 15 19:45:07 BST tiger% who >> events 24 tiger% cat events Sun May 15 19:45:07 BST 2005 beusdul pts/20 May 15 08:21 (host bulldogdsl.com) svigkoi pts/3 May 15 18:52 (dsl access.as9105.com) w pts/4 May 15 19:00 ( dsl.pipex.com) 25 tiger% SAMPLE OUTPUT 5.5: APPENDING FILES THROUGH OUTPUT REDIRECTION Assuming that we want to maintain a file called events that logs the date and time of the system and any users that are logged in the tiger UNIX server. First, we executed the command date > events by redirecting its output to the file events. This resulted in the generation of the file with contents as printed out by the more events command. As, we want to have a list of users logged in, we executed the command who >> events. The output of this command was redirected from the standard output and placed in the file events. The file events was not actually deleted but it was appended with additional data. The cat events execution printed out the contents of the appended file. PAGE 8

9 5.1.4 MULTIPLE COMMAND EXECUTION AND REDIRECTION We can also execute several commands at once and redirect their standard output to a given file. This can be carried out by the use of the semicolon (;) and brackets symbols ( ( ), ( ) ). Assuming that we need to generate a file that contains information about time and users logged in a UNIX server. A possible solution elaborated previously is to execute first the command date > logfile where date is a UNIX command and logfile corresponds to a give file name. The execution of this command will generate the file and it will store in it information about current date and time. Then is is obvious, we need to execute who >> logfile. This will append the file logfile with information outputted by the who command. However, the approach illustrated in sample output 5.6 refers to a different way. EXAMPLE (date;who) > events 2 tiger% (date;who) > events 3 tiger% more events Wednesday May 18 21:15:00 BST 2005 beusdul pts/7 May 18 09:24 (host bulldogdsl.com) svigkoi pts/20 May 18 20:36 (dsl access.as9105.com) w pts/35 May 18 21:14 (tiger) w pts/33 May 18 20:46 (snake.gotadsl.co.uk) svigkoi pts/34 May 18 20:48 (dsl access.as9105.com) w dtremote May 18 08:23 (ncs-202-pc17.oac.wmin.ac.uk:0) w pts/3 May 18 08:23 (ncs-202-pc17.oac.wmin.ac.uk:0.0) w pts/4 May 18 08:23 (ncs-202-pc17.oac.wmin.ac.uk:0.0) w pts/18 May 18 08:23 (ncs-202-pc17.oac.wmin.ac.uk:0.0) w pts/5 May 18 08:23 (ncs-202-pc17.oac.wmin.ac.uk:0.0) w dtremote May 18 16:40 (ws-hd-pc04.irs.wmin.ac.uk:0) w pts/40 May 18 16:41 (ws-hd-pc04.irs.wmin.ac.uk:0.0) 4 tiger% ^C SAMPLE OUTPUT 5.6: APPENDING FILES THROUGH OUTPUT REDIRECTION By executing command (date;who) > events, the shell executed the command date first and buffered its output. Then, in a similar way executed the second command who and added into the buffer its output. As, we indicated that output should be redirected into file events; the shell wrote the contents of the buffer into the corresponding file. The brackets indicated the precedence of the execution. Alternatively, they dictated the execution of both commands whose output, then, was redirected. Note that in sample output 5.6, we described the execution of two UNIX commands. However, we indice PAGE 9

10 brackets we can enter as many commands as we wish to execute separated by the semicolon symbol. 5.2 COMMAND PIPING So far, we had the opportunity to work with input and output redirection. For example, we considered a process output redirection to a file and its input redirection from a file or the keyboard and so on. At this stage, we may have an obvious question which is Can we redirect a command s output to another one?. The answer is simply Yes, we can do that with two ways; an indirect and a direct one. Let us consider the first approach which we are familiar with. For example, let us assume that we wish to count the number of users who are currently logged in. Therefore, we need to use the who and wc -l commands. However, as we are not familiar with the notion of process piping, we initially execute the first command and redirect its output to a file called mylog. EXAMPLE who, wc l 14 tiger% who > mylog 15 tiger% wc -l < mylog 9 16 tiger% SAMPLE OUTPUT 5.7: APPENDING FILES THROUGH OUTPUT REDIRECTION Next, we redirected into standard input the contents of the file mylog into wc -l. This resulted in having as output number 9 which refers to the number of users currently logged in tiger UNIX machine. The second way is to use the piping technique. This means that in a similar fashion with the input/output redirection, we redirect standard output of a process as standard input into another one. In order to indicate the shell out intentions we use the symbol ( ). The syntax of piping technique is described as follows (Syntax 5.2). SYNTAX piping % command A command B [NOTE THAT THE SYMBOL % REFERS TO THE COMMAND PROMPT.] SYNTAX 5.2: SYNTAX: PIPING TECHNIQUE PAGE 10

11 Although syntax 5.2 described the piping technique for two commands, namely command A and command B, we can pipe more than two processes. In order to understand the piping technique in a more clear way, we provide an illustration (figure 5.6) FIGURE 5.6: PROCESS PIPING In figure 5.6, we can see that standard input (stdin[0] A ) is redirected into process A. The execution of this process results in the generation of some output ((stdout[1] A ) which is redirected into process B as standard input (stdin[0] B ). Then the execution of command B generates is redirected to standard output (stdout[1] B ). Note that, the execution of pipelined commands may result to the generation of errors. These are handled by the standard error (stderr[2]). 5 tiger% who wc -l 11 6 tiger% who wc -l > nusers 7 tiger% more nusers 11 8 tiger% SAMPLE OUTPUT 5.8: USING PIPED PROCESSES As illustrated in sample output 5.8, the standard output of who command was redirected as standard input in the wc l command. This means that who gave us a list of all users then the wc l count all lines in the given list and showed result on our terminal window. Moreover, as also shown, we can use piped processes with redirection. For example, we executed again the piped command who wc l but we redirected its output into a file called nusers. PAGE 11

12 5.3 PROCESSES AND PROCESS CONTROL From knowledge and experience gathered so far, we are able to understand that commands allow us to interact with the UNIX operating system. This kind of interaction ranges from entering commands for getting information about the state of the system to executing commands that change the state of the file system i.e. deleting or creating files and directories. Whatever, we do we need to remember that when we execute commands, we give certain instructions to the system which, then, takes some action. TERM process Typically, the commands we have considered so far reflect to sequences of bytes, at a very low level, that can be understood by UNIX machines. However, there is also a second kind of commands that are executed in a different way. These are first interpreted by specific programs, known as interpreters, and executed then by the interpreters themselves. Both of these types of commands are known as processes. At any time, each process that is under execution should be moved out or fetched along with any necessary data, from the machine s memory and sent to the CPU for processing. After this step, any output given based on a set of these instructions will be stored back into the machine s memory. At, this point, the obvious question is that Yes, but what happens if a process requires lots of processing resources or its execution takes long time; moreover what happens to other processes waiting for execution? You said UNIX is a multi-tasking operating system but here we can see a kind of sequential processing! The point here is that processes have different requirements and their execution time differs. However, in order to maintain the notion of multitasking, processes are given a certain amount of time to complete their execution while they are being processed. If their execution cannot be completed at the given time slot, the operating system s kernel, just suspends their execution and starts executing another command. Then, based upon some kernel s criteria, a suspended process is fetched again from memory, for further processing. When, a process finishes execution is removed from machine s processor(s) and killed. The managing of processes is carried out by the kernel while this task is transparent from end users. PAGE 12

13 TERM system process Now, it is clear that, processes can be in one of several states. For example, they can be in execution state or they can be suspended. At any time or when their execution is finished, they are just killed and removed from a machine. This typically happens to all processes which are initialised by endusers. Whilst, some process known as system-processes run at all times in order to make a machine operable. For instance, some of these include the kernel itself and the shell. Although the control of these processes is transparent from end-users and managed with an autonomous way, users can also manage some of these processes. In general, processes initialised in a shell have two types. They may be part of the shell itself or they can be not. In the former case, processes will be interpreted and executed by the shell and after execution the command prompt will return back to end-users. In the latter, a new process will be created by invoking code stored in the machine while the shell which is a process itself will be suspended. Its execution will be resumed after the execution of the new process. For example, by invoking one of the UNIX editors i.e. emacs, a new process starts execution known as emacs. This makes the command prompt stop operating and it will be returned back to us after emacs process finishes execution or killed. Typically, users can control the execution of processes initialised in a shell. They can obtain information about processes that are running; they can suspend some of them or even kill them. In order to get information about all processes initialised, a user needs to execute the ps command where ps stands for process. Its syntax is described as follows: ps [options] SYNTAX 5.3: SYNTAX OF ps COMMAND There are several options that can be used with ps command. Some of these options are summarized in table 5.2. However, by typing ps only, we can obtain information about each process that corresponds to its unique process identifier (PID), displayed in the first column; the name of the terminal from which a process is running and can be controlled (TTY); the third column displays the amount of processing time, a process has consumed while the last column refers to the name of each process. The following sample output shows processes running in a shell. PAGE 13

14 10 tiger% ps PID TTY TIME CMD pts/5 0:00 ps pts/5 0:00 csh 11 tiger% ps -lf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 8 O w ? :27:18 pts/5 0:00 ps -lf 8 S w ? 203? 11:03:12 pts/5 0:00 -csh 12 tiger% ps -al F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 8 O ? 144 pts/5 0:00 ps 8 S ? 1268? pts/17 0:01 pine 8 S ? 326? pts/17 0:00 bash 8 S ? 289? pts/18 0:00 telnet 8 S ? 1339? pts/23 0:01 pine 8 S ? 1745? pts/20 0:10 pine 13 tiger% SAMPLE OUTPUT 5.9: USING PIPED PROCESSES As shown, ps displayed some information about processes running in a shell. Moreover, we also used several options to obtain more information. For example, -lf instructed the shell to display a long listing of processes and their current priorities. However, at this stage we are only interested to know some of this information. For example, we may consider the PPID (Parent process ID) which initialised a process. Moreover, we may also consider the STIME (start time) of a process, its current priority (PRI) and the UI (user ID) of the user who initialised a process. OPTIONS DESCRIPTION -a Lists information about all processes most frequently requested -e Lists information about every process now running. -f It generates a full listing -l It generates a long listing -P Prints the number of the processor to which the process is bound, under column header, PSR. TABLE 5.2: SOME PS OPTIONS We can also get information about all processes that are currently running. These include system processes and processes generated by anyone who uses a UNIX machine. In a similar way, we can obtain information regarding PIDs, users who initialised each process (USER), processes priorities (PRI), memory each process consumes (SIZE) also expressed in percentage rate (%MEM), processor power (%CPU). Moreover, we also get PAGE 14

15 information about each process name (COMMAND) and its processing time (TIME). load averages: 0.04, 0.04, :12:52 72 processes: 70 sleeping, 1 stopped, 1 on cpu CPU states: % idle, % user, % kernel, % iowait, % swap Memory: 2048M real, 1403M free, 151M swap in use, 4458M swap free PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND root K 2784K sleep 0: % in.ftpd svigkoi K 1264K cpu/1 0: % top root K 2880K sleep 0: % sshd w K 6720K sleep 0: % emacs root K 3272K sleep 0: % in.ftpd 234 root K 3232K sleep 0: % nscd svigkoi K 792K sleep 0: % tee svigkoi K 1384K sleep 0: % csh root K 2920K sleep 0: % sshd root K 2776K sleep 0: % in.ftpd 198 root K 2912K sleep 12: % automountd 3085 nobody M 10M sleep 1: % xfs 302 root K 3792K sleep 1: % cfenvd 174 root K 1880K sleep 0: % inetd w M 74M sleep 0: % soffice.bin SAMPLE OUTPUT 5.10: USING top COMMAND For example, we can see from sample output 5.10 that there are 70 processes which are running with 70 of them sleeping, one which is stopped and one which is being processed by the central processing unit of the corresponding machine (tiger). The second line refers to various statistics of tiger machine expressed as percentages. Then, the top command displayed a list of processes. For example, let us consider the first described process. It has process ID and it was initialised by user root who is the administrator of this machine. Its priority is 59, its size is 3168Kbytes and it is currently sleeping. Moreover, considering its name, ftpd, it is clear that it refers to the ftp server process which actually allows us to connect to this machine through FTP and transfer files WORKING WITH PROCESSES: BACKGROUND AND FOREGROUND So far, we use the command prompt to execute various UNIX commands. Some of them after finishing execution return the command prompt to us indicating that the system is ready to accept another command. However, using some other commands or applications, we have to exit in order to get back the command prompt. For instance, this happens when we PAGE 15

16 use emacs editor. In this case, it is said that a command runs in the foreground. As this is not very efficient, we may instruct the shell to execute a command in the background. In fact, this will allow us to use our command prompt for executing other processes, as well. In order to instruct the shell for sending a command to the background we use the ampersand symbol (&) places at the end of a command. 24 tiger% ls & [1] tiger% StarOffice52 ffjuser30 mydir one1.2 Final Trash file myn2 public_html Folder after mail. [1] Done ls 25 tiger% SAMPLE OUTPUT 5.11: SENDING COMMANDS IN THE BACKGROUND The execution of ls command was sent in the background. This is shown because after sending this command for execution, we were informed about its job number ([1]) and its process identifier (PID) which is Then, the command prompt was given back to us. As, ls finished executing, we received a notice informing us about this event. The most important point here is that when we send processes in the background we get our shell prompt back, almost immediately. Note that usually ls displays the content of a directory and automatically exits. Although the provided example is not very indicative, it shows the concept described previously CONTROLLING PROCESSES The sleep command can suspend execution of the shell for a given time. For example, we can type sleep 20 in order to suspend execution of the shell for 20 seconds. 29 tiger% date;sleep 20;date Thu May 19 12:58:20 BST 2005 Thu May 19 12:58:40 BST tiger% PAGE 16

17 SAMPLE OUTPUT 5.12: SUSPENDING EXECUTION It is probably understood that sleep is not very useful. However, it is a precise example that demonstrates how we can interact with and control processes in the UNIX operating system KILLING PROCESSES TERM signal Each UNIX process can communicate with another one through the exchange of simple messages. These messages, known as signals, are expressed as single bytes and can instruct processes to perform various operations. Typically, with this approach the kernel has the ability to manipulate processes existed in a machine. For example, the kernel can suspend the execution of a process or it can kill it, if this is necessary. Moreover, it can also schedule processes by indicating their execution order, when they should be executed and their priority. Users can also send messages to processes that have been initialised by them, as well. At this stage, we are interested only about killing processes that have been sent in the background. Consider for example that command sleep 5000 has been sent for background execution. Although, we can use ps to check out that this process is running, we may also wish to stop its execution. Therefore, we need to send a message to sleep command that instructs it to exit. This can be carried out by the signal SIGKILL that when received, it will cause sleep to be destroyed almost immediately. The command responsible for sending these kinds of messages is the kill UNIX command. kill <PID> SYNTAX 5.4: SYNTAX OF kill COMMAND As shown, in order to kill a process we use the kill command while we enter as an argument the process identifier of the process we wish to terminate. In order to find out the process identifier of the corresponding process, we may use the ps command first. Here is a sample output (5.13). 30 tiger% sleep 5000& [1] tiger% ps PID TTY TIME CMD PAGE 17

18 17791 pts/5 0:00 ps pts/5 0:00 sleep pts/5 0:00 csh 32 tiger% kill tiger% [1] Terminated sleep tiger% SAMPLE OUTPUT 5.13: KILLING PROCESSES First, we sent to in the background the command sleep 5000&. Then, we entered ps, in order to find out its process identifier and then we instructed the shell to terminate this process. When, the termination completed, the shell informed us by displaying an event notification. There are several motivational aspects regarding the termination of a process. For example, we may have sent a process for background execution by mistake or a process started running for a long time and it consumes lots of computational power. At last but not least, we may terminate a process if it is not responding anymore (crashed). 5.4 PRACTICE 1. Crate a file called dayandtime and then insert information about today s date and time; use an appropriate command to display the contents of this file in your terminal window; create a hard link of this file called hdayandtime; make sure the new file has been created; display the contents of your hard linked file; delete the source; append your hard-linked file with information about day and time; display the contents of your hard-linked file; create a soft link of your hdayandtime file with name sdayandtime; make sure your new file has been created; PAGE 18

19 display its contents in the terminal window; append your soft linked file with information about date and time; display the contents of your soft linked file in the terminal window; delete your soft link file; delete your hdayandtime file. [NOTE: MAKE SURE THAT YOU WILL NOT USE ANY EDITORS. INSTEAD, USE THE APPROPRIATE REDIRECTION CHARACTER(S) FOUND IN.1.] 2. Create a log file, called userslog that contains information about users who are currently logged in tiger.westminster.ac.uk machine. Your file should contain the following: Date and time; All users logged in; [HINT: USE THE > REDIRECTION CHARACTER] 3. Repeat exercise one (1), at this time your file with the same filename (do not append it) should include: An integer number that reflects the number of users who are currently logged in tiger.westminster.ac.uk. 4. Delete file userslog using the appropriate UNIX command. Then create a file called userslog again and: enter the date and time; all users logged in tiger.westminster.ac.uk; display the file contents in your terminal window; log in jaguar.westminster.ac.uk; append your file userslog with day and time as obtained from jaguar.westminster.ac.uk machine; the additional information should include all users logged in jaguar.westminster.ac.uk. display the contents of your appended file in your terminal window; delete your file. PAGE 19

20 5. Execute the appropriate command that displays information about processes which run under your current shell. Forward, the commands output: to the terminal window; execute it again and redirect it to a file called myprocesses; diplay the file contents on the terminal window; initialise a sleep command with duration seconds and send it in the background; call the appropriate command to get a long listing of processes which are currently running. The output of this command should be displayed in your terminal window; call the appropriate command again but redirect its output into the file myprocesses; redirect the contents of myprocesses into the file bmyprocesses. Do not use the copy command. display the contents of bmyprocesses in the terminal window; terminate the sleep command initialised previously. Get a long listing of processes which are currently running. Dipplay them in your terminal window. Make sure the sleep command is terminated. delete all files created. 6. Using the file bankacc created by you in the last section (section 4, exercise 5), redirect its output into a file called dates. Your dates file should include only the transaction dates made on the shared bank account. 7. In a similar fashion to exercise 6, cretate a file with all account holders who made transactions. Your file should be called tnames. 8. Use the find command to look for a file in your current directory and all subdirectories i.e. search for mynotes file. Create a directory called noaccess and change its access rights so no one can access it. Then, use the find command to search again for mynotes file. Diplay any outout on the terminal window. Then: PAGE 20

21 Redirect find s output in a file called search. Could you forward standard error or standard error and standard output into this file? Use C shell and Bourne shell. PAGE 21

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W PROGRAM CONTROL, FILE ARCHIVING, ENVIRONMENT AND SCRIPTS S E C T I O N O V E R V I E W Continuing from last section, we are going to learn about the following concepts: controlling programs; working with

More information

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W AN INTRODUCTION TO SHELLS S E C T I O N O V E R V I E W Continuing from last section, we are going to learn about the following concepts: understanding quotes and escapes; considering the importance of

More information

Unix Processes. What is a Process?

Unix Processes. What is a Process? Unix Processes Process -- program in execution shell spawns a process for each command and terminates it when the command completes Many processes all multiplexed to a single processor (or a small number

More information

Sperimentazioni I LINUX commands tutorial - Part II

Sperimentazioni I LINUX commands tutorial - Part II Sperimentazioni I LINUX commands tutorial - Part II A. Garfagnini, M. Mazzocco Università degli studi di Padova 24 Ottobre 2012 Streams and I/O Redirection Pipelines Create, monitor and kill processes

More information

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

Most of the work is done in the context of the process rather than handled separately by the kernel

Most of the work is done in the context of the process rather than handled separately by the kernel Process Control Process Abstraction for a running program Manages program s use of memory, cpu time, and i/o resources Most of the work is done in the context of the process rather than handled separately

More information

Exploring UNIX: Session 5 (optional)

Exploring UNIX: Session 5 (optional) Exploring UNIX: Session 5 (optional) Job Control UNIX is a multi- tasking operating system, meaning you can be running many programs simultaneously. In this session we will discuss the UNIX commands for

More information

S E C T I O N O V E R V I E W

S E C T I O N O V E R V I E W FILES AND DIRECTORIES: ADVANCED CONCEPTS S E C T I O N O V E R V I E W In this section, we will learn about: understanding soft (symbolic) links; understanding hard links; working with soft and hard links;

More information

I/O and Shell Scripting

I/O and Shell Scripting I/O and Shell Scripting File Descriptors Redirecting Standard Error Shell Scripts Making a Shell Script Executable Specifying Which Shell Will Run a Script Comments in Shell Scripts File Descriptors Resources

More information

Introduction to Linux

Introduction to Linux Introduction to Linux Mukesh Pund Principal Scientist, NISCAIR, New Delhi, India History In 1969, a team of developers developed a new operating system called Unix which was written using C Linus Torvalds,

More information

CST Algonquin College 2

CST Algonquin College 2 The Shell Kernel (briefly) Shell What happens when you hit [ENTER]? Output redirection and pipes Noclobber (not a typo) Shell prompts Aliases Filespecs History Displaying file contents CST8207 - Algonquin

More information

Linux System Administration

Linux System Administration System Processes Objective At the conclusion of this module, the student will be able to: Describe and define a process Identify a process ID, the parent process and the child process Learn the PID for

More information

Introduction to UNIX Shell Exercises

Introduction to UNIX Shell Exercises Introduction to UNIX Shell Exercises Determining Your Shell Open a new window or use an existing window for this exercise. Observe your shell prompt - is it a $ or %? What does this tell you? Find out

More information

High Performance Computing Lecture 11. Matthew Jacob Indian Institute of Science

High Performance Computing Lecture 11. Matthew Jacob Indian Institute of Science High Performance Computing Lecture 11 Matthew Jacob Indian Institute of Science Agenda 1. Program execution: Compilation, Object files, Function call and return, Address space, Data & its representation

More information

Introduction: What is Unix?

Introduction: What is Unix? Introduction Introduction: What is Unix? An operating system Developed at AT&T Bell Labs in the 1960 s Command Line Interpreter GUIs (Window systems) are now available Introduction: Unix vs. Linux Unix

More information

Command-line interpreters

Command-line interpreters Command-line interpreters shell Wiki: A command-line interface (CLI) is a means of interaction with a computer program where the user (or client) issues commands to the program in the form of successive

More information

CSC UNIX System, Spring 2015

CSC UNIX System, Spring 2015 CSC 352 - UNIX System, Spring 2015 Study guide for the CSC352 midterm exam (20% of grade). Dr. Dale E. Parson, http://faculty.kutztown.edu/parson We will have a midterm on March 19 on material we have

More information

Creating a Shell or Command Interperter Program CSCI411 Lab

Creating a Shell or Command Interperter Program CSCI411 Lab Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell

More information

System Programming. Introduction to Unix

System Programming. Introduction to Unix Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Introduction

More information

CPSC 457 OPERATING SYSTEMS MIDTERM EXAM

CPSC 457 OPERATING SYSTEMS MIDTERM EXAM CPSC 457 OPERATING SYSTEMS MIDTERM EXAM Department of Computer Science University of Calgary Professor: Carey Williamson March 9, 2010 This is a CLOSED BOOK exam. Textbooks, notes, laptops, calculators,

More information

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

CSC209H Lecture 1. Dan Zingaro. January 7, 2015 CSC209H Lecture 1 Dan Zingaro January 7, 2015 Welcome! Welcome to CSC209 Comments or questions during class? Let me know! Topics: shell and Unix, pipes and filters, C programming, processes, system calls,

More information

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection 1 Files 1.1 File functions Opening Files : The function fopen opens a file and returns a FILE pointer. FILE *fopen( const char * filename, const char * mode ); The allowed modes for fopen are as follows

More information

User Commands ps ( 1 )

User Commands ps ( 1 ) NAME ps report process status SYNOPSIS ps [-aacdefjllpy] [-g grplist] [-n namelist] [-o format]... [-p proclist] [-s sidlist] [-t term] [-u uidlist] [-U uidlist] [-G gidlist] DESCRIPTION The ps command

More information

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1 Review of Fundamentals Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 GPL the shell SSH (secure shell) the Course Linux Server RTFM vi general shell review 2 These notes are available on

More information

5/20/2007. Touring Essential Programs

5/20/2007. Touring Essential Programs Touring Essential Programs Employing fundamental utilities. Managing input and output. Using special characters in the command-line. Managing user environment. Surveying elements of a functioning system.

More information

Crash Course in Unix. For more info check out the Unix man pages -orhttp://www.cs.rpi.edu/~hollingd/unix. -or- Unix in a Nutshell (an O Reilly book).

Crash Course in Unix. For more info check out the Unix man pages -orhttp://www.cs.rpi.edu/~hollingd/unix. -or- Unix in a Nutshell (an O Reilly book). Crash Course in Unix For more info check out the Unix man pages -orhttp://www.cs.rpi.edu/~hollingd/unix -or- Unix in a Nutshell (an O Reilly book). 1 Unix Accounts To access a Unix system you need to have

More information

Introduction to the Shell

Introduction to the Shell [Software Development] Introduction to the Shell Davide Balzarotti Eurecom Sophia Antipolis, France What a Linux Desktop Installation looks like What you need Few Words about the Graphic Interface Unlike

More information

The Unix Shell & Shell Scripts

The Unix Shell & Shell Scripts The Unix Shell & Shell Scripts You should do steps 1 to 7 before going to the lab. Use the Linux system you installed in the previous lab. In the lab do step 8, the TA may give you additional exercises

More information

Linux Tutorial #6. -rw-r csce_user csce_user 20 Jan 4 09:15 list1.txt -rw-r csce_user csce_user 26 Jan 4 09:16 list2.

Linux Tutorial #6. -rw-r csce_user csce_user 20 Jan 4 09:15 list1.txt -rw-r csce_user csce_user 26 Jan 4 09:16 list2. File system access rights Linux Tutorial #6 Linux provides file system security using a three- level system of access rights. These special codes control who can read/write/execute every file and directory

More information

Review of Fundamentals

Review of Fundamentals Review of Fundamentals 1 The shell vi General shell review 2 http://teaching.idallen.com/cst8207/14f/notes/120_shell_basics.html The shell is a program that is executed for us automatically when we log

More information

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc. Appendix A GLOSSARY SYS-ED/ Computer Education Techniques, Inc. $# Number of arguments passed to a script. $@ Holds the arguments; unlike $* it has the capability for separating the arguments. $* Holds

More information

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen Introduction to Unix The Windows User perspective Wes Frisby Kyle Horne Todd Johansen What is Unix? Portable, multi-tasking, and multi-user operating system Software development environment Hardware independent

More information

CHAPTER 2 THE UNIX SHELLS

CHAPTER 2 THE UNIX SHELLS CHAPTER 2 THE UNIX SHELLS The layers in a UNIX system is shown in the following figure. system call interface library interface user interface Users Standard utility programs (shell, editors, compilers,

More information

5/8/2012. Specifying Instructions to the Shell Chapter 8

5/8/2012. Specifying Instructions to the Shell Chapter 8 An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing the functioning of the shell. Employing advanced user features. Specifying Instructions to the Shell Chapter

More information

Module 8 Pipes, Redirection and REGEX

Module 8 Pipes, Redirection and REGEX Module 8 Pipes, Redirection and REGEX Exam Objective 3.2 Searching and Extracting Data from Files Objective Summary Piping and redirection Partial POSIX Command Line and Redirection Command Line Pipes

More information

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p. 2 Conventions Used in This Book p. 2 Introduction to UNIX p. 5 An Overview

More information

Introduction to the Linux Command Line January Presentation Topics

Introduction to the Linux Command Line January Presentation Topics 1/22/13 Introduction to the Linux Command Line January 2013 Presented by Oralee Nudson ARSC User Consultant & Student Supervisor onudson@alaska.edu Presentation Topics Information Assurance and Security

More information

Oxford University Computing Services. Getting Started with Unix

Oxford University Computing Services. Getting Started with Unix Oxford University Computing Services Getting Started with Unix Unix c3.1/2 Typographical Conventions Listed below are the typographical conventions used in this guide. Names of keys on the keyboard are

More information

Useful Unix Commands Cheat Sheet

Useful Unix Commands Cheat Sheet Useful Unix Commands Cheat Sheet The Chinese University of Hong Kong SIGSC Training (Fall 2016) FILE AND DIRECTORY pwd Return path to current directory. ls List directories and files here. ls dir List

More information

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi Bash Scripting Alessandro Barenghi Dipartimento di Elettronica, Informazione e Bioingegneria Politecnico di Milano alessandro.barenghi - at - polimi.it April 28, 2015 Introduction The bash command shell

More information

85321, Systems Administration Chapter 6: The shell

85321, Systems Administration Chapter 6: The shell Chapter 6 Introduction The Shell You will hear many people complain that the UNIX operating system is hard to use. They are wrong. What they actually mean to say is that the UNIX command line interface

More information

Lec 1 add-on: Linux Intro

Lec 1 add-on: Linux Intro Lec 1 add-on: Linux Intro Readings: - Unix Power Tools, Powers et al., O Reilly - Linux in a Nutshell, Siever et al., O Reilly Summary: - Linux File System - Users and Groups - Shell - Text Editors - Misc

More information

Bamuengine.com. Chapter 7. The Process

Bamuengine.com. Chapter 7. The Process Chapter 7. The Process Introduction A process is an OS abstraction that enables us to look at files and programs as their time image. This chapter discusses processes, the mechanism of creating a process,

More information

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1 Review of Fundamentals Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 The CST8207 course notes GPL the shell SSH (secure shell) the Course Linux Server RTFM vi general shell review 2 Linux

More information

Week 5 Lesson 5 02/28/18

Week 5 Lesson 5 02/28/18 Week 5 Lesson 5 02/28/18 Important Announcements Extra Credits If you haven t done so, send your pictures to risimms@cabrillo.edu for 3 points EXTRA CREDIT. Join LinkedIn for 3 points Perkins/VTEA Survey

More information

Chapter-3. Introduction to Unix: Fundamental Commands

Chapter-3. Introduction to Unix: Fundamental Commands Chapter-3 Introduction to Unix: Fundamental Commands What You Will Learn The fundamental commands of the Unix operating system. Everything told for Unix here is applicable to the Linux operating system

More information

An Introduction to Unix Power Tools

An Introduction to Unix Power Tools An to Unix Power Tools Randolph Langley Department of Computer Science Florida State University August 27, 2008 History of Unix Unix Today Command line versus graphical interfaces to COP 4342, Fall History

More information

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts CSCI 2132 Software Development Lecture 3: Unix Shells and Other Basic Concepts Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 10-Sep-2018 (3) CSCI 2132 1 Introduction to UNIX

More information

UNIX Kernel. UNIX History

UNIX Kernel. UNIX History UNIX History UNIX Kernel 1965-1969 Bell Labs participates in the Multics project. 1969 Ken Thomson develops the first UNIX version in assembly for an DEC PDP-7 1973 Dennis Ritchie helps to rewrite UNIX

More information

UNLV Computer Science Department CS 135 Lab Manual

UNLV Computer Science Department CS 135 Lab Manual UNLV Computer Science Department CS 135 Lab Manual prepared by Lee Misch revised July 2013 CS 135 Lab Manual Content Page Introduction 3 CS Computer Accounts. 3 TBE B361 Computer Basics. 3 Choosing an

More information

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda Essential Unix and Linux! Perl for Bioinformatics, 140.636! F. Pineda Generic computer architecture Memory Storage Fig. 1.2 From Designing Embedded Hardware, 2 nd Ed. by John Catsoulis OS concepts Shell

More information

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute Shells The UNIX Shells How shell works Fetch command Analyze Execute Unix shells Shell Originator System Name Prompt Bourne Shell S. R. Bourne /bin/sh $ Csh Bill Joy /bin/csh % Tcsh Ken Greer /bin/tcsh

More information

Programs. Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic

Programs. Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic Programs Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic Types of Processes 1. User process: Process started

More information

The input can also be taken from a file and similarly the output can be redirected to another file.

The input can also be taken from a file and similarly the output can be redirected to another file. Filter A filter is defined as a special program, which takes input from standard input device and sends output to standard output device. The input can also be taken from a file and similarly the output

More information

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering ENG224 Information Technology Part I: Computers and the Internet Laboratory 2 Linux Shell Commands and vi Editor

More information

Chap2: Operating-System Structures

Chap2: Operating-System Structures Chap2: Operating-System Structures Objectives: services OS provides to users, processes, and other systems structuring an operating system how operating systems are designed and customized and how they

More information

Basics. I think that the later is better.

Basics.  I think that the later is better. Basics Before we take up shell scripting, let s review some of the basic features and syntax of the shell, specifically the major shells in the sh lineage. Command Editing If you like vi, put your shell

More information

Operating Systems. Lecture 07. System Calls, Input/Output and Error Redirection, Inter-process Communication in Unix/Linux

Operating Systems. Lecture 07. System Calls, Input/Output and Error Redirection, Inter-process Communication in Unix/Linux Operating Systems Lecture 07 System Calls, Input/Output and Error Redirection, Inter-process Communication in Unix/Linux March 11, 2013 Goals for Today Interprocess communication (IPC) Use of pipe in a

More information

find starting-directory -name filename -user username

find starting-directory -name filename -user username Lab 7: Input and Output The goal of this lab is to gain proficiency in using I/O redirection to perform tasks on the system. You will combine commands you have learned in this course using shell redirection,

More information

Processes. System tasks Campus-Booster ID : **XXXXX. Copyright SUPINFO. All rights reserved

Processes. System tasks Campus-Booster ID : **XXXXX.  Copyright SUPINFO. All rights reserved Processes System tasks Campus-Booster ID : **XXXXX www.supinfo.com Copyright SUPINFO. All rights reserved Processes Your trainer Presenter s Name Title: **Enter title or job role. Accomplishments: **What

More information

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell: Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed performs the actions Example:

More information

UNIX Essentials Featuring Solaris 10 Op System

UNIX Essentials Featuring Solaris 10 Op System A Active Window... 7:11 Application Development Tools... 7:7 Application Manager... 7:4 Architectures - Supported - UNIX... 1:13 Arithmetic Expansion... 9:10 B Background Processing... 3:14 Background

More information

ITST Searching, Extracting & Archiving Data

ITST Searching, Extracting & Archiving Data ITST 1136 - Searching, Extracting & Archiving Data Name: Step 1 Sign into a Pi UN = pi PW = raspberry Step 2 - Grep - One of the most useful and versatile commands in a Linux terminal environment is the

More information

My Favorite bash Tips and Tricks

My Favorite bash Tips and Tricks 1 of 6 6/18/2006 7:44 PM My Favorite bash Tips and Tricks Prentice Bisbal Abstract Save a lot of typing with these handy bash features you won't find in an old-fashioned UNIX shell. bash, or the Bourne

More information

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell.

What is the Shell. Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell. What is the Shell Whenever you login to a Unix system you are placed in a program called the shell. All of your work is done within the shell. The shell is your interface to the operating system. It acts

More information

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems 1 Shells are cool Unix [3] embraces the philosophy: Write programs that do one thing and do it well. Write programs to work together.

More information

CMU MSP 36602: Intro to UNIX and Scripting: Part 1

CMU MSP 36602: Intro to UNIX and Scripting: Part 1 CMU MSP 36602: Intro to UNIX and Scripting: Part 1 H. Seltman March 28, 2018 I. Overview a. UNIX is an operating system which is a competitor to and partial ancestor of MS-DOS, MS-Windows, and Mac OSX.

More information

System Administration

System Administration Süsteemihaldus MTAT.08.021 System Administration UNIX shell basics Name service DNS 1/69 Command Line Read detailed manual for specific command using UNIX online documentation or so called manual (man)

More information

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu CPSC 341 OS & Networks Processes Dr. Yingwu Zhu Process Concept Process a program in execution What is not a process? -- program on a disk A process is an active object, but a program is just a file It

More information

Design Overview of the FreeBSD Kernel CIS 657

Design Overview of the FreeBSD Kernel CIS 657 Design Overview of the FreeBSD Kernel CIS 657 Organization of the Kernel Machine-independent 86% of the kernel (80% in 4.4BSD) C code Machine-dependent 14% of kernel Only 0.6% of kernel in assembler (2%

More information

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent? Design Overview of the FreeBSD Kernel CIS 657 Organization of the Kernel Machine-independent 86% of the kernel (80% in 4.4BSD) C C code Machine-dependent 14% of kernel Only 0.6% of kernel in assembler

More information

Removing files and directories, finding files and directories, controlling programs

Removing files and directories, finding files and directories, controlling programs Removing files and directories, finding files and directories, controlling programs Laboratory of Genomics & Bioinformatics in Parasitology Department of Parasitology, ICB, USP Removing files Files can

More information

A Brief Introduction to the Linux Shell for Data Science

A Brief Introduction to the Linux Shell for Data Science A Brief Introduction to the Linux Shell for Data Science Aris Anagnostopoulos 1 Introduction Here we will see a brief introduction of the Linux command line or shell as it is called. Linux is a Unix-like

More information

Perl and R Scripting for Biologists

Perl and R Scripting for Biologists Perl and R Scripting for Biologists Lukas Mueller PLBR 4092 Course overview Linux basics (today) Linux advanced (Aure, next week) Why Linux? Free open source operating system based on UNIX specifications

More information

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12) Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12) Objective: Learn some basic aspects of the UNIX operating system and how to use it. What is UNIX? UNIX is the operating system used by most computers

More information

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2) BANK ON & SHELL PROGRAMMING-502 (CORE PAPER-2) TOPIC 1: VI-EDITOR MARKS YEAR 1. Explain set command of vi editor 2 2011oct 2. Explain the modes of vi editor. 7 2013mar/ 2013 oct 3. Explain vi editor 5

More information

System Programming. Unix Shells

System Programming. Unix Shells Content : Unix shells by Dr. A. Habed School of Computer Science University of Windsor adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 Interactive and non-interactive

More information

Lab 2: Linux/Unix shell

Lab 2: Linux/Unix shell Lab 2: Linux/Unix shell Comp Sci 1585 Data Structures Lab: Tools for Computer Scientists Outline 1 2 3 4 5 6 7 What is a shell? What is a shell? login is a program that logs users in to a computer. When

More information

EECS2301. Lab 1 Winter 2016

EECS2301. Lab 1 Winter 2016 EECS2301 Lab 1 Winter 2016 Lab Objectives In this lab, you will be introduced to the Linux operating system. The basic commands will be presented in this lab. By the end of you alb, you will be asked to

More information

Linux Command Line Interface. December 27, 2017

Linux Command Line Interface. December 27, 2017 Linux Command Line Interface December 27, 2017 Foreword It is supposed to be a refresher (?!) If you are familiar with UNIX/Linux/MacOS X CLI, this is going to be boring... I will not talk about editors

More information

CSCI 2132 Software Development. Lecture 4: Files and Directories

CSCI 2132 Software Development. Lecture 4: Files and Directories CSCI 2132 Software Development Lecture 4: Files and Directories Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 12-Sep-2018 (4) CSCI 2132 1 Previous Lecture Some hardware concepts

More information

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based. Unix tutorial Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based. Terminal windows You will use terminal windows to enter and execute

More information

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 Bashed One Too Many Times Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 What is a Shell? The shell interprets commands and executes them It provides you with an environment

More information

h/w m/c Kernel shell Application s/w user

h/w m/c Kernel shell Application s/w user Structure of Unix h/w m/c Kernel shell Application s/w. user While working with unix, several layers of interaction occur b/w the computer h/w & the user. 1. Kernel : It is the first layer which runs on

More information

Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal

Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal 2012-10-01 what is a process? an abstraction! you can think of it as a program in the midst of

More information

Unix/Linux: History and Philosophy

Unix/Linux: History and Philosophy Unix/Linux: History and Philosophy History and Background Multics project Unix Linux Multiplexed Information and Computing Service Collaborative venture between General Electric, Bell Telephone Labs, and

More information

Lecture-4. Introduction to Unix: More Commands, Boot-up Actions and X Window

Lecture-4. Introduction to Unix: More Commands, Boot-up Actions and X Window Lecture-4 Introduction to Unix: More Commands, Boot-up Actions and X Window What You Will Learn We continue to give more information about the fundamental commands of the Unix operating system. We also

More information

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file ULI101 Week 05 Week Overview Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file head and tail commands These commands display

More information

Assignment clarifications

Assignment clarifications Assignment clarifications How many errors to print? at most 1 per token. Interpretation of white space in { } treat as a valid extension, involving white space characters. Assignment FAQs have been updated.

More information

The Classical OS Model in Unix

The Classical OS Model in Unix The Classical OS Model in Unix Nachos Exec/Exit/Join Example Exec parent Join Exec child Exit SpaceID pid = Exec( myprogram, 0); Create a new process running the program myprogram. int status = Join(pid);

More information

Chapter 9: Process management. Chapter 9 Process management

Chapter 9: Process management. Chapter 9 Process management Chapter 9: Process management Chapter 9 Process management Last revised: 19/7/2004 Chapter 9 Outline In this chapter we will learn about: Processes and process concepts Examining processes Adjusting process

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs. CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs

More information

Unix Tutorial Haverford Astronomy 2014/2015

Unix Tutorial Haverford Astronomy 2014/2015 Unix Tutorial Haverford Astronomy 2014/2015 Overview of Haverford astronomy computing resources This tutorial is intended for use on computers running the Linux operating system, including those in the

More information

(MCQZ-CS604 Operating Systems)

(MCQZ-CS604 Operating Systems) command to resume the execution of a suspended job in the foreground fg (Page 68) bg jobs kill commands in Linux is used to copy file is cp (Page 30) mv mkdir The process id returned to the child process

More information

INSE Lab 1 Introduction to UNIX Fall 2017

INSE Lab 1 Introduction to UNIX Fall 2017 INSE 6130 - Lab 1 Introduction to UNIX Fall 2017 Updated by: Paria Shirani Overview In this lab session, students will learn the basics of UNIX /Linux commands. They will be able to perform the basic operations:

More information

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group. CMPS 12L Introduction to Programming Lab Assignment 2 We have three goals in this assignment: to learn about file permissions in Unix, to get a basic introduction to the Andrew File System and it s directory

More information

Unix Shells and Other Basic Concepts

Unix Shells and Other Basic Concepts CSCI 2132: Software Development Unix Shells and Other Basic Concepts Norbert Zeh Faculty of Computer Science Dalhousie University Winter 2019 Shells Shell = program used by the user to interact with the

More information

Linux shell scripting Getting started *

Linux shell scripting Getting started * Linux shell scripting Getting started * David Morgan *based on chapter by the same name in Classic Shell Scripting by Robbins and Beebe What s s a script? text file containing commands executed as a unit

More information

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND Prof. Michael J. Reale Fall 2014 Finding Files in a Directory Tree Suppose you want to find a file with a certain filename (or with a filename matching

More information