User Tools

Site Tools


opus:spring2012:rhensen:unixpart2

unix Keywords

Source Code

Definition

A text file containing a program that is written out in a particular programming language. This file itself is not executable.

Demonstration

This is the source code of a simple program in C.

#include <stdio.h>
 
int main()
{
        puts("Hello, World!\n");
        return(0);
}

Compiler

Definition

A compiler is able to create executable code from a source code file.

Demonstration

This shows how to compile a source code file called “helloC.c” into an executable file called “helloC”.

lab46:~/devel$ gcc -o helloC helloC.c

Pattern Matching

Definition

Certain Unix utilities support regular expressions, which can be used to define a pattern of characters. Utilities that support this will then be able to find strings of characters that adhere to this pattern.

Demonstration

This shows how pattern matching can be used to find lines of text that match a defined pattern.

lab46:~$ cat pattern
1. dog
2. cow
3. horse
4. cat
lab46:~$ grep c.. pattern
2. cow
4. cat

Regular Expression

Definition

A regular expression is a means of defining a formula that can be used as a stand in for a string of text. These are used to specify a pattern so that lines of text following that pattern can be found.

Demonstration

This shows how lines of text can be matched to a regular expression. The regular expression is defined as a string that begins with the letters c or d followed by two more characters.

lab46:~$ cat pattern
1. dog
2. cow
3. horse
4. cat
lab46:~$ grep [c-d].. pattern
1. dog
2. cow
4. cat

Job Control

Definition

Job control allows the user to view and manage the multiple processes that are running on the system.

Demonstration

The ps command can be used to show running processes on the system.

lab46:~$ ps
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
rhensen   1236  0.0  0.0  13592     8 pts/0    SNs  Jan25   0:00 /bin/bash
rhensen   1257  0.0  0.1  42608  2332 pts/0    SN+  Jan25   9:21 irssi
rhensen  20632  0.0  0.1  13640  2012 pts/27   SNs  01:30   0:00 -bash
rhensen  21082  0.0  0.0   8588  1000 pts/27   RN+  02:04   0:00 ps u

Suspend

Definition

Suspending a process allows that process to be paused, but not stopped entirely. This is done by issuing the SUSPEND character to the program (CTRL-Z).

Demonstration

The jobs command can be used to show programs that are running. Stopped jobs have been suspended, which means they are still in memory but are not currently running.

lab46:~$ jobs
[1]+  Stopped                 man man

Text Processing

Definition

Text processing involves the creation and manipulation of the ASCII data within text files.

Demonstration

There are various programs available that can be used to create or edit text. In the example below, three text editors are shown. If the text file called “text” already exists it will be opened for manipulation in the program. If the file does not exist it will be created.

lab46:~$vi text
lab46:~$vim text
lab46:~$pico text

The VI Editor

Definition

VI is a text editing utility created for Unix. It is a modal text editor, which means that there are two modes that it can operate in. The command mode interprets input as commands and the insert mode interprets input as text that should be typed into the file.

Demonstration

This is what a VI screen generally looks like. The lines of text are displayed at the top of the screen and commands that are issued are displayed at the bottom.

Hello. This is text.
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"text" [New File]                                             0,0-1         All

unix Objective

unix Objective

To become more familiar with how the Unix shell operates.

Definition

Since I have been working with Unix in a command line environment, learning to use the features and understanding what the system is doing is less transparent that it is when working in a GUI. I want to obtain a better understanding of how Unix works and what happens when commands are issued.

Method

I will feel that I have gained an understanding in this area when I have a firm understanding of how the Unix system operates apart from its utilities.

Measurement

I would like to become more familiar with various aspects of the Unix environment, such as how to manage processes, how to find files, and make use of the device files.

Analysis

The lab that involved job management was particularly useful in this area. I learned a lot about how to see what processes are running on the system and the different ways to manage them. The differences between killing, suspending, and interrupting a process for example are important concepts for working with the operating system. I also found it interesting that Unix allows communication between users by writing to a device file that the user is connected through. I feel that I have also become more comfortable with using utilities like the find command and grep. I believe that these concepts have enhanced my overall understanding of what makes the operating system work when it has been broken down.

opus/spring2012/rhensen/unixpart2.txt · Last modified: 2012/04/02 06:22 by rhensen