Agenda Administrative Issues Link of the Week Review Week Two Information This Week’s Expected...
-
Upload
delilah-cox -
Category
Documents
-
view
226 -
download
1
Transcript of Agenda Administrative Issues Link of the Week Review Week Two Information This Week’s Expected...
Agenda
Administrative Issues Link of the Week Review Week Two Information This Week’s Expected Outcomes Next Lab Assignment Break-Out Problems Upcoming Deadlines Lab Assistance, Questions, and Answers
Link of the week
https://freedom-to-tinker.com/blog/felten/source-code-and-object-code
What is object code?http://www.linfo.org/object_code.htmlObject File Format
Link of the weekWhat is object code?An object file is a file containing object code, meaning relocatable format machine code that is usually not directly executable. Object files are produced by an assembler, compiler, or other language translator, and used as input to the linker, which in turn typically generates an executable or library by combining parts of object files. There are various formats for object files, and the same object code can be packaged in different object files.
Link of the week/export/home/dandrear/Winter_2015_Solutions>od -c zombie.c0000000 # i n c l u d e < s t d l i b0000020 . h > \n # i n c l u d e < s y0000040 s / t y p e s . h > \n # i n c l0000060 u d e < u n i s t d . h > \n \n0000100 / * \n * \n * C o m p i l e0000120 s c r i p t : c c z o m b0000140 i e . c - o z o m b i e \n0000160 * o m m a n d : p s - e0000200 - o p i d , p p i d , s t a t0000220 , c m d \n * \n * / \n i n t0000240 m a i n ( ) \n { \n p i d _0000260 t c h i l d _ p i d ; \n \n0000300 c h i l d _ p i d = f o r k0000320 ( ) ; \n i f ( c h i l d0000340 _ p i d > 0 ) { \n0000360 s l e e p ( 1 2 0 ) ; \n }0000400 \n e l s e { \n e x0000420 i t ( 0 ) ; \n } \n r e t u0000440 r n 0 ; \n } \n \n
Link of the week#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
/*
*
* Compile script: cc zombie.c -o zombie
* ommand: ps -e -o pid,ppid,stat,cmd
*
*/
int main ()
{
pid_t child_pid;
child_pid = fork ();
if (child_pid > 0) {
sleep (120);
}
else {
exit (0);
}
return 0;
}
Link of the weekObject code produced by a compilerProgrammers write programs in a high-level language called source code (Java or C Language). The source code consists of instructions in a particular language, like C, C++, or Java. However, computers can only execute instructions written in low-level language called machine language.
Link of the weekWhat is Object File Format?
An object file format is a computer file format used for the storage of object code and other related data.
There are many different object file formats; originally each type of computer had its own unique format, but with the advent of UNIX software portability, some formats, such as COFF and ELF became the de facto standard used on different kinds of operating systems. It is possible for the same file format to be used both as linker input and output, and thus as the library and executable file format.
Link of the week
SourceFile
SourceFile
SourceFile
SourceFile
SourceFile
Object File
Object File
ObjectFile
Object File
ObjectFile
LinkerRuntimeLibrary
ExecutableProgram
Source/Object/Executable Drawing
Course expected outcome Learning Outcomes (Week four)Write Perl scripts, including variables, control flow,
and regular expression syntax
UNIX Operating SystemUNIX file system
When we talk about a UNIX file system, we are actually referring to an area of physical memory represented by a single i-list. A UNIX machine may be connected to many different file systems, each with its own i-list. One of those i-lists points to a special storage area, known as the root file system. The root file system contains the files for the operating system itself, and must be available at all times.
UNIX Operating System
Some file systems are considered removable. A removable file systems can be attached, or mounted, to the root file system. Typically, an empty directory is created on the root file system as a mount point, and a removable file system is attached to that empty directory. When you issue a cd command to access the files and directories of a mounted removable file system, your file operations will be controlled through the i-list of the removable file system.
UNIX Operating System The purpose of the i-list is to provide the
operating system with a map into the memory of some physical storage device (disk drive). The map is continually being updated, as the files are created and removed, and as they grow and shrink in size. Thus, the mechanism of mapping must be very flexible and robust in order to accommodate drastic changes in the number and size of files. The i-list is stored in a known location, on the same memory storage device that it maps.
UNIX Operating SystemEach entry in an i-list is called an inode. An
inode is a data structure that provides the flexibility to track the changing file system. The inodes contain the information necessary to get information from the storage device, which typically communicates in fixed-size disk blocks.
UNIX Operating SystemAn inode contains 10 direct pointers, which point
to disk blocks on the storage device. In addition, each inode also contains one indirect pointer, one double indirect pointer, and one triple indirect pointer. The indirect pointer points to a block of direct pointers. The double indirect pointer points to a block of indirect pointers, and the triple indirect pointer points to a block of double indirect pointers. By structuring the pointers in a geometric fashion, a single inode can represent a very large file.
UNIX Operating System
It should make more sense to view a UNIX directory as a list of i-numbers, each i-number referencing a specific inode on a specific i-list. The operating system traces its way through a file path by following the inodes until it reaches the direct pointers that contain the actual location of the file on the storage device.
UNIX Operating System
UNIX inode attributesThe POSIX standard mandates file system behavior that
is strongly influenced by traditional UNIX file systems. Regular files must have the following attributes:
• The size of the file in bytes.• Device ID (this identifies the device containing the file).• The User ID of the file's owner.• The Group ID of the file.• The file mode which determines the file type and how the
file's owner, its group, and others can access the file.
UNIX Operating System
• Additional system and user flags to further protect the file (limit its use and modification).
• Timestamps telling when the inode itself was last modified (ctime, inode change time), the file content last modified (mtime, modification time), and last accessed (atime, access time).
• A link count telling how many hard links point to the inode.
• Pointers to the disk blocks that store the file's contents (see inode pointer structure).
UNIX Operating System
The UNIX file system relies on data structures about files, beside the file content. The inode content information is considered metadata data that describes data. Each file has a number associated with it, which is called an inode number.
UNIX Operating System
UNIX Operating System
UNIX Operating System
UNIX Operating System
UNIX Operating SystemUNIX directory In UNIX, directories are files which contain
information about other files. A UNIX directory is a file whose data is an array or list of (filename, i-node#) pairs.
– It has an owner, group owner, size, access permissions, etc.
– Many file operations can be used on directories– As a file, a directory has an i-node type structure.– A flag in the structure indicates its type.
UNIX Operating SystemUNIX directory
Unlike other files, the kernel imposes a structure on directory files using the UNIX command mkdir.
A directory is a sequence of lines, a sequence of directory entries of variable length where each line contains an inode number and a file name mapping: <filename, inode #>
UNIX Operating SystemUNIX command mkdir sub_dir The creation of a sub_dir directory file and an inode for it• An inode number and name are added to the parent directory
file Directory sub_dir
133 .
23145 ..
9645 dump 45270 script
UNIX Operating System133 .
23145 ..
9645 dump
45270 script
9645 .
133 ..
635 core1
2022 core2
45270 .
133 ..
7467 ksh
2324 csh
UNIX Operating SystemDot and dot-dot files
“.” and “..” are stored as ordinary file names with inode numbers pointing to the correct directory files.
UNIX Operating SystemFile system directory structure The file system directory structure is a link between the inode
hash list and the directory files.
The root “/” inode is always number 2. The root “/” directory file data block is located thru inode number 2.
Directory file entries include each entry <filename, inode number>. Where file name is the local (unqualified) directory or regular file name within the directory and inode number is an index into the inode hash array.
The (inode number) inode in the hash list entry has pointer to the data block of the subsequent regular file or directory file data block.
UNIX Operating SystemFile system directory structure
If it is a directory file, the directory data blocks are read for the next <filename, inode number>, and the process repeats.
UNIX Operating SystemFile system directory structure
If it is a regular file, the data blocks are located and read.
This process also explains the difference between hard links and soft links. A hard link directory entry is a direct pointer to a file inode. A soft link is a pointer to another directory entry.
In a link, rm clears the directory record. Usually, this means that the inode number is set to 0 but the file may not be affected.
The file inode is only deleted when the last link to it is removed; the data block for the file is also deleted (reclaimed).
UNIX Operating SystemDisk drive
UNIX Operating SystemFile system data structure Disk drive
File system
inode inode inode . . . inode
Boot Block
Super Block
I-List Data blocks for files, and directories.
Partition Partition Partition
UNIX Operating SystemHard link
UNIX Operating SystemSoft link
UNIX Operating System
Link (ln) command
The ln command is used to create a hard and soft link. Hard link (physical):
ln original_file.txt hard_link.txt
Soft link (symbolic):ln –s original_file.txt soft_link.txt
UNIX Operating SystemUNIX directory Directory data is stored as binary, and cannot
be displayed using the cat command. But some older versions of UNIX allow: od -c dir-name.
Although directories are files, UNIX permissions – rwx- have slightly different meanings:
- r, lists directory contents- w, add a file to the directory- x, cd to the directory
UNIX Operating SystemUser process accessing data
Given the file name. To get to the file’s control block (FCB), use the file system catalog (Open, Close, Set_Attribute)
The catalog maps a file name to the file control block– Checks permissions
file_handle=open(file_name): – Search the catalog and bring file control block into
the memory– UNIX: in-memory file control block: in-core i-
node
UNIX Operating SystemUser process accessing data
Use the file control block to get to the desired offset within the file data:(CREATE, DELETE, SEEK, TRUNCATE)
close(file_handle): release file control block from memory
UNIX Operating SystemWhat is a filter?
A UNIX filter command performs an operation or manipulation of the input text from a file. Standard in and out are typically used during this operation.
UNIX Command Line Filters awk, cat, cut, expand, compress, fold, grep, head, nl,
perl, pr, sed, sh, sort, split, strings, tail, tac, tee, tr, uniq, and wc
UNIX Operating System
File System Filters cat, cd, chmod, chown, chgrp, cksum, cmp, cp, dd,
du, df, fsck, fuser, ln, ls, lsattr, lsof, mkdir, mount, mv, pwd, rm, rmdir, split, touch, umask
Processes Filters
at, chroot, cron, exit, kill, killall, nice, pgrep, pidof, pkill, ps, pstree, sleep, time, top, and wait
UNIX Operating SystemTest Command
A common way to set up a condition for the if command is with the test command.
test condition or [ condition ]
The test command evaluates the condition and returns 0 or 1, depending on the results of the test.The brackets work exactly like the test condition. The open bracket is a link to test.
UNIX Operating SystemConstructing Conditions
-s file -r file -w file -S file-x file -f file -d file
Examples: if [ ! –f /etc/quotatab ]Does the plain file named /etc/quotatab not exist?
If [ -d /etc/rc0.d ]Is the /etc/rc0.d name a directory?
UNIX Operating SystemConstructing Conditions
-S file = True if the file exists and its size is greater than zero.-s file = True if the file exists and is a socket.-w file = True if the file exists and is writable.-x file = True if the file exists and is executable.-f file = True if the file exists and is a regular file-d file = True if the file exists and is a directory.
UNIX Operating SystemPerl and Shell Similarities
Perl scalar@ARGV ~ Shell $#Perl $ARGV[0] ~ Shell $1Perl $ARGV[1] ~ Shell $2Perl unless(scalar(@ARGV)==2) ~ Shell if [ $# != 2]All Perl statements are terminated with a “;”Perl exit 0 is returned if execution was successful.Perl exit 1 is returned if execution fails.
UNIX Operating SystemPerl syntax
$? - this variable contains the return value # - precedes a comment statement in Perl\n - new line syntax“ …” $strexp = “This text is considered as a string”;‘ …’ $charexp = ‘a’;` …` $cmdexp = `ls –l`;@ARGV – array containing command line arguments$_ - default implied scalar
UNIX Operating System
Relational operatorsThere are two types of relational operators. One class
operates on numeric values, the other on string values.
Relational operatorsNumeric String Meaning > gt Greater than >= ge Greater than or equal < lt Less than <= le Less than or equal
UNIX Operating System
Equality Operators
Numeric String Meaning == eq Equal to != ne Not equal to cmp Comparison, sign
results-1 if the left operand is less than right operand 0 If both operands equal to right operand 1 If the left operand is greater right operand
UNIX Operating SystemEquality Operatorsif ( $count != 5 ) { print "The counter is NOT equal to 5.\n"; } if ( $response eq 'YES‘ )
{print "You said YES";}else{
print "I don't know what you said, but it wasn't YES";}
UNIX Operating SystemInitial Perl designPerl is designed to
- Process text data - Perform pattern matching - Utilize string handling tasks
Perl is available on many platforms - UNIX- Linux- HP-UX- Red Hat Linux Enterprise
UNIX Operating SystemPerl utilizes two types of categories
Singular variables that represent a single-value. The variable prefix symbol for a scalar is the $.
Plural variables are ones that contain multiple-values. Arrays and hashes are two multi-valued variables. The variable prefix symbol for an array and hash are @ and %, respectively.
UNIX Operating System
Perl data types
$answer = 42; (an integer)$pi = 3.14159265; (a “real” number)$animal = “horse”; (string)$statement = “I exercise my $animal”;
(string with interpolation)$amount = ‘It cost me $5.00’;
(string without interpolation)
$cwd = `pwd`; (string output from a command)
UNIX Operating SystemInitialize Perl array
Definition: An array is an ordered list of scalars, accessed by the scalar’s position in the list.
@garage = (“car”, “mower”, “broom”); @persons = (“Will”, “Karim”, “Asma”, “Jay”);$count = @persons;
UNIX Operating System
Perl Formats
if ( … ){
…}
while ( … ){
…}
UNIX Operating System
Perl Formats
for ( initialize variable, test variable, increment variable){
…}
UNIX Operating System
Perl formats
if ($append) { open(MYOUTFILE, ">filename.out");
#open for write, overwrite }else { open(MYOUTFILE, ">> filename.out"); #open for
write, append }
UNIX Operating SystemPoints of interest
UNIX uses a hierarchical file system for storing files. This system consists of a "root" directory which is made up of sub-directories which in turn are made up of sub-directories.
All UNIX directories contain a dot (.) and dot-dot (..) files.
UNIX Operating SystemDemonstrate
Perl script:./week_four.pl
UNIX Operating System
Moving Around in UNIXpwdrmdirtelnetsftptalkpasswdwfingerwrite
Break-out problems
$strexp = “This text is considered as a string”;$intexp = 10;$floatptexp = 2.54;$charexp = ‘a’;$cmdexp = `ls –l`;$argexp = (“two”, “four”, “six”);@array_exp = (“Jackie”, “Vicki”, “Alex”);$array [0] = “new value”;$a = $b + 5;$container = @container; ($map{blue}, $map{orange}, $map{jade}) = (0xff0000, 0x00ff00, 0x0000ff0);
Hands-On-InformationLab Assignment 3-1, Advanced Scripting, due May
24, 2015.Lab Assignment 4-1, Simple Perl Exercise, due May
31, 2015.Read Chapters 1 and 2 in Essential System
Administration text.Read Module Two listed under the course Web site.Everyone should have received a Perl Quick
Reference document and script logic for Lab Assignment 4-1.
After class assistance
Questions?Comments?Concerns?
After each Franklin Live session, I will remain on the session to provide assistance unless otherwise indicated.
Lab Assistance available by phone and/or email