Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC400 Week Three Professor Robert D’Andrea

Similar presentations


Presentation on theme: "ITEC400 Week Three Professor Robert D’Andrea"— Presentation transcript:

1 ITEC400 Week Three Professor Robert D’Andrea

2 Agenda Administrative Issues This Week’s Expected Outcomes Next Lab Assignment Break-Out Problems Upcoming Deadlines Lab Assistance, Questions, and Answers

3 This Week’s Expected Out Come
Learning Outcome Object code System dumps (octal, hex, and binary) File system Write Perl scripts, including variables, control flow, and regular expression syntax

4 UNIX Operating System What is object code?
What is object code? Object File Format

5 UNIX Operating System What 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.

6 UNIX Operating System Object code produced by a compiler Programmers 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.

7 UNIX Operating System

8 UNIX Operating System 0000000 # i n c l u d e < s t d l i b
/export/home/dandrear/Winter_2018_Solutions>od -c zombie.c # i n c l u d e < s t d l i b h > \n # i n c l u d e < s y s / t y p e s h > \n # i n c l u d e < u n i s t d h > \n \n / * \n * \n * C o m p i l e s c r i p t : c c z o m b i e c o z o m b i e \n * o m m a n d : p s e o p i d , p p i d , s t a t , c m d \n * \n * / \n i n t m a i n ( ) \n { \n p i d _ t c h i l d _ p i d ; \n \n c h i l d _ p i d = f o r k ( ) ; \n i f ( c h i l d _ p i d > ) { \n s l e e p ( ) ; \n } \n e l s e { \n e x i t ( ) ; \n } \n r e t u r n ; \n } \n \n

9 UNIX Operating System /export/home/dandrear/Fall_2017_Solutions>xxd zombie.c : 0a23 696e 636c c c69 .#include <stdli : 622e 683e 0a23 696e 636c c73 b.h>.#include <s : f e68 3e0a e63 ys/types.h>.#inc : 6c c 756e e68 3e0a lude <unistd.h> : 0a2f 2a0a 202a a0a 202a a ./*. * *. * * : f6d c a Compile script: : a6f 6d e63 202d 6f20 cc zombie.c -o : 7a6f 6d a20 2a a 206f zombie. * * o : 6d6d 616e 643a d65 202d 6f20 mmand: ps -e -o : c c c 636d pid,ppid,stat,cm 00000a0: 640a 202a a 0a20 2a d. * *. * 00000b0: a 2f0a 696e d61 696e 2028 */.int main ( 00000c0: 290a 7b0a f c ).{. pid_t chil 00000d0: 645f b 0a0a c 645f d_pid;.. child_ 00000e0: d20 666f 726b b 0a20 pid = fork (); f0: c64 5f e if (child_pid > : b0a c ) {. sleep : b 0a20 207d 0a c73 (120);. }. els : b0a e {. exit (0) : 3b0a d0a e b0a ;. }.return 0; : 7d0a 0a }..

10 UNIX Operating System /export/home/dandrear/Fall_2017_Solutions>xxd -b /tmp/zombie_c_hex | less : : : 0a c: e : c : e: c : a: c : #in : clude c: <stdli : : : e: e : e 0a a: e : c : c: c7

11 UNIX Operating System #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;

12 UNIX Operating System C program to take input from user using scanf #include <stdio.h> main() { int number; printf("Enter an integer\n"); scanf("%d",&number); printf("Integer entered by you is %d\n", number); return 0; }

13 UNIX Operating System What 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.

14 UNIX Operating System

15 UNIX Operating System What does a file system provide? A file system controls the a way data is stores and retrieved. Without this control, it would be difficult to know where one piece of information starts and ends. Separating data into pieces and assigning it a name, isolates the information and makes it identifiable. The isolated piece of information is better known as a file. The organization and logical rules used to manage these groups of files is called a "file system".

16 UNIX Operating System What does a file system provide?

17 UNIX Operating System A File Allocation Table (FAT32) File System The FAT file system was a general purpose file system, which supports both fixed and removable media. It uses the Windows-compatible FAT file format so that removable media can be exchanged with PCs and other Windows-compatible file systems. FAT was the most popular simple and small file system. It is a legacy file system that was used extensively throughout the MS-DOS years.

18 UNIX Operating System A NTFS File System  NTFS is a completely different file system from FAT that was introduced with first version of Windows NT in Designed to address many of FAT’s deficiencies, it provides for greatly increased privacy and security.

19 UNIX Operating System Flash File System  Is a simple, power fail-safe file system for NAND and NOR flash chips. It supports very large flash devices, yet has a small memory footprint.

20 UNIX Operating System Flash Logger  Is a simple flash logger that provides high-speed, reliable data logging to NAND or NOR flash memory. It has extremely small code and data footprints. Logging data is a common operation in embedded systems, and warrants a good solution. 

21 UNIX Operating System UNIX file system The UNIX file system actually refers 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.

22 UNIX Operating System

23 UNIX Operating System UNIX file 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.

24 UNIX Operating System UNIX file 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.

25 UNIX Operating System UNIX file system Each 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.

26 UNIX Operating System UNIX file system An 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.

27 UNIX Operating System UNIX file 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.

28 UNIX Operating System UNIX inode attributes
POSIX is a standard that mandates file system behavior that 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.

29 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).

30 UNIX Operating System UNIX file 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.

31 UNIX Operating System

32 UNIX Operating System

33 UNIX Operating System

34 UNIX Operating System UNIX 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.

35 UNIX Operating System UNIX directory
Unlike other files, the kernel imposes a structure on directory files using the UNIX command mkdir. 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. 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 #>

36 UNIX Operating System UNIX directory
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.

37 UNIX Operating System script UNIX 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

38 UNIX Operating System 133 . 23145 .. 9645 dump 45270 script 9645 . 133
635 core1 2022 core2 45270 . 133 .. 7467 ksh 2324 csh

39 UNIX Operating System Dot and Dot-Dot files
“.” and “..” are stored as ordinary file names with inode numbers pointing to the correct directory files. Every Unix directory contains the name “.” (dot), which is a name that leads right back to the directory in which it is found. Every directory contains the name “..” (dot dot), which is a name that leads to the unique parent directory of the directory in which it is found. The ROOT directory is the only directory that is its own parent: both “.” and “..” are the same in the ROOT directory. If you go to the parent of the ROOT directory, you are still in the ROOT directory.

40 UNIX Operating System Root Directory Since a slash always separate name components, if a pathname starts with a slash, the nameless “ROOT” directory is assumed to begin the pathname. The ROOT directory has no name. It is the root of the entire Unix file system tree. A pathname starting with a slash is called an absolute pathname, since it always starts at the ROOT.

41 UNIX Operating System Absolute and relative pathnames A pathname that starts with a leading slash (indicating that the path starts at the nameless ROOT directory) is called an absolute pathname. Your current working directory has no effect on an absolute pathname, because an absolute pathname always starts at the ROOT and doesn’t depend on your current directory. All other pathnames (with no leading slash) are called relative pathnames. These relative pathnames are evaluated relative to the current working directory. Relative pathnames (no leading slash) always start in the current directory, not in the ROOT directory.

42 UNIX Operating System Absolute and relative pathnames Because relative pathnames start in the current working directory, relative pathnames act as if the current working directory were inserted in front of the pathname. Putting ./ in front of any relative pathname does not change what the pathname refers to; the pathname is still relative to the current directory and still refers to the same thing.

43 UNIX Operating System File 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.

44 UNIX Operating System File system directory structure
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. If it is a directory file, the directory data blocks are read for the next <filename, inode number>, and the process repeats.

45 UNIX Operating System

46 UNIX Operating System File 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).

47 UNIX Operating System Disk drive

48 UNIX Operating System File system data structure Disk drive File system Partition Boot Block Super Block I-List Data blocks for files, and directories. inode . . .

49 UNIX Operating System Hard link

50 UNIX Operating System Soft link

51 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

52 UNIX Operating System (hard link)

53 UNIX Operating System (symbolic link)

54 UNIX Operating System UNIX 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

55 UNIX Operating System User 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

56 UNIX Operating System User 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

57 UNIX Operating System What 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

58 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

59 UNIX Operating System Test 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.

60 UNIX Operating System Constructing Conditions -s file -r file -w file -S file -x file -f file -d file Examples: if [ ! –f /etc/quotatab ] Definition: Does the plain file named /etc/quotatab not exist? Example: if [ -d /etc/rc0.d ] Definition: Is the /etc/rc0.d name a directory?

61 UNIX Operating System Constructing 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.

62 UNIX Operating System Perl and Shell Similarities Perl ~ Shell $# Perl $ARGV[0] ~ Shell $1 Perl $ARGV[1] ~ Shell $2 Perl ~ 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.

63 UNIX Operating System Perl 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 – array containing command line arguments $_ - default implied scalar

64 UNIX Operating System Relational operators There are two types of relational operators. One class operates on numeric values, the other on string values. Numeric String Meaning > gt Greater than >= ge Greater than or equal < lt Less than <= le Less than or equal

65 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

66 UNIX Operating System Equality Operators if ( $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";

67 UNIX Operating System Initial Perl design Perl 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

68 UNIX Operating System Perl 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 and %, respectively.

69 UNIX Operating System Perl data types $answer = 42; (an integer) $pi = ; (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)

70 UNIX Operating System Initialize Perl array Definition: An array is an ordered list of scalars, accessed by the scalar’s position in the = (“car”, “mower”, = (“Will”, “Karim”, “Asma”, “Jay”); $count

71 UNIX Operating System Perl Formats if ( … ) { … } while ( … )

72 UNIX Operating System Perl Formats for ( initialize variable, test variable, increment variable) { … }

73 UNIX Operating System Perl formats if ($append) { open(MYOUTFILE, ">filename.out"); #open for write, overwrite } else { open(MYOUTFILE, ">> filename.out"); #open for write, append

74 UNIX Operating System Points of interest A hierarchical file system is how drives, folders, and files are displayed on an operating system. In a hierarchical file system, the drives, folders, and files are displayed in groups, which allows the user to see only the files they're interested in seeing.

75 UNIX Operating System Demonstrate Perl script: ./week_four.pl

76 UNIX Operating System Moving Around in UNIX pwd rm telnet sftp talk passwd finger write

77 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 ($map{blue}, $map{orange}, $map{jade}) = (0xff0000, 0x00ff00, 0x0000ff0);

78 Hands-On-Information
Read Chapters 1, 2, and 3 in Perl Programming Read Module 5 an 6 listed under the course web page.

79 After class assistance
Questions? Comments? Concerns? After each Franklin Live session, I will remain on the session to provide assistance unless otherwise indicated.

80

81 Lab Assistance available by phone and/or email


Download ppt "ITEC400 Week Three Professor Robert D’Andrea"

Similar presentations


Ads by Google