Scripting Languages Scripting Languages Awk Simple Awk Program Simple Awk Program General Structure of an Awk Program Awk One-Li

Total Page:16

File Type:pdf, Size:1020Kb

Scripting Languages Scripting Languages Awk Simple Awk Program Simple Awk Program General Structure of an Awk Program Awk One-Li Scripting Languages Awk Higher-level languages. Named for its three developers: Scripting Languages More compact for small programs. Alfred Aho Often not suitable for large systems. Peter Weinberger COMS W4115 The more popular ones: Brian Kernighan Prof. Stephen A. Edwards Awk Good for data file manipulation. I use it for computing Spring 2002 grades and other simple tasks. Columbia University Perl Department of Computer Science Python Tcl Bourne Shell Simple Awk Program Simple Awk Program General structure of an Awk program Input file. Each line a record. Space-separated fields: Beth 10.0 0 pattern { action } Kathy 14.0 10 employee, pay rate, hours worked pattern { action } Beth 10.0 0 . 3rd field . Dan 9.75 0 z}|{ Kathy 14.0 10 $3 > 0 { print $1, $2 * $3 } Mark 10.0 20 | {z } | {z } awk scans an input file one line at a time and, in order, Susie 8.25 18 pattern action runs each action whose pattern matches. Run on the awk program Kathy 140 Patterns: $3 > 0 { print $1, $2 * $3 } BEGIN, END True before and after the file. expression Condition produces /regular expression/ String pattern match && Kathy 140 pattern pattern Mark 200 pattern || pattern Boolean operators Susie 148.5 ! pattern Awk One-Liners Statistics in Awk Associative Arrays: Word Counter Print every line #!/bin/awk -f { gsub(/[.,:;!(){}]/, "") # remove punctuation BEGIN { n = 0; s = 0; ss = 0;} for ( i = 1 ; i <= NF ; i++ ) { print } NF == 1 { n++; s += $1; ss += $1 * $1; } count[$i]++ Print the first and third fields of each line END { } print n " data points" END { for (w in count) { print $1, $3 } m = (s+0.0) / n; print m " average" print count[w], w | "sort -rn" sd = sqrt( (ss - n * m * m) / ( n - 1.0)) } Print every line with three fields print sd " standard deviation" NF == 3 { print } } Run on the Tiger reference manual produces 1 103 the 5 6 data points 58 of Print a line number before every line 10 51 is Run on gives 6.16667 average 3 49 and { print NR, $0 } 3.92003 standard deviation 49 a 7 35 expression 11 32 The 29 = Perl Wordcount in Perl Understandable wordcount in Perl Larry Wall’s #!/usr/bin/perl #!/usr/bin/perl Practical Extraction and Report Language while(<>) { while($line = <>) { chop; chop($line); or s/.,:;!(){}]//g; $line =˜ s/.,:;!(){}]//g; Pathologically Eclectic Rubbish Lister @words = split; @words = split(/\s+/, $line); Larger, more flexible language than Awk. Good for text foreach $word (@words) { foreach $word (@words) { processing and other tasks. Strange semantics. Henious $count{$word}++; $count{$word}++; syntax. } } } } Excellent regular-expression support. More complicated open(SORTER, "| sort -nr"); open(SORTER, "| sort -nr"); data structures possible (even classes). foreach $word (keys %count) { foreach $word (keys %count) { print SORTER print SORTER $count{$word}, " ", $word,"\n"; $count{$word}, " ", $word,"\n"; } } “There’s More Than One Way To Do It” So Why Perl? Python Perhaps too many. Equivalent ways to print STDIN: Perhaps the most popular scripting language. Perl designed by a sane man. while (<STDIN>) { print; } Despite its flaws, it’s very powerful. Very clean syntax and semantics. print while <STDIN> Almost has a good type system. Large collection of libraries (but not as big as Perl’s). while (defined(($_ = <STDIN>)) { print $_; } for (;<STDIN>;) { print; } Very few things can't be done in Perl. Regular expression support (but not as integrated as print $_ while defined($_ = <STDIN>); Fast, flexible interpreter. Perl’s.) Many Perl statements come in prefix and postfix form Ability to make virtually every Unix system call. Binary while (...) ... data manipulation. ... while ... Ported everywhere. if (...) ... ... if ... Very, very extensive collection of libraries. Database ... unless ... access. CGI/HTML for the web. Math. IPC. Time. Wordcount in Python Python Classes Python’s Merits #!/usr/bin/env python class Complex: Good support for programming-in-the-large: def __init__(self, realpart, imagpart): self.r = realpart import fileinput, re, string, os self.i = imagpart Packages with separate namespaces; Exceptions; def add(self, a): Classes count = {} self.r = self.r + a.r for line in fileinput.input(): self.i = self.i + a.i Persistent datastructures (pickling) line = re.sub(r’[.,:;!(){}]’,"",line) def p(self): High-level: lists, strings, associative arrays, iterators for word in string.split(line): print "%g + %gi" % (self.r,self.i) if not count.has_key(word): count[word] = 1 x = Complex(1,2) Good collection of libraries: else: y = Complex(2,3) x.p() Operating-system access (files, directories, etc.); count[word] = count[word] + 1 x.add(y) x.p() String manipulation; Curses; Databases; Networking f = os.popen("sort -nr",’w’) Prints (CGI, HTTP, URL, mail/Mime, HTML); Tk; for word in count.keys(): f.write(’%d %s\n’ % (count[word], word) ) 1 + 2i Cryptography; System-specific (Windows, Mac, SGI, 3 + 5i POSIX) Python vs. Perl Tcl Tcl Syntax Python can be the more verbose language, but Perl can John Ousterhout’s Tool Command Language was Shell-like command syntax: be cryptic. originally intended to be grafted on to an application to command argument argument . make it controllable. Regular expression support more integrated with All data is strings (incl. numbers and lists) language in Perl. Since become a general-purpose scripting language. Its Macro-like variable substitution: syntax is quite simple, although rather atypical for a Perl better-known. programming language. set foo "123 abc" Probably comparable execution speeds. bar 1 $foo 3 Tk, a Tcl package, provide graphical user interface More “tricks” possible in Perl; Python more disciplined. widgets. Tcl/Tk may be the easiest way to write a GUI. Command substitution: Python has the much cleaner syntax and semantics; I Tk has been connected to Perl and Python as well. set foo 1 know which language’s programs I’d rather maintain. set bar 2 puts [eval $foo + $bar]; # Print 3 Wordcount in Tcl Nifty Tcl Features Tk #!/usr/bin/env tclsh Associative arrays “Hello World” in Tk. while {[gets stdin line] >= 0} { set count(Stephen) 1 button .b -text "Hello World" -command "exit" regsub -all {[.,:;!(){}]} $line "" line pack .b foreach word $line { Lists if {![info exists count($word)]} { set count($word) 1 lappend foo 1 } else { incr count($word) lappend foo 2 } foreach i $foo { puts $i } ; # print 1 then 2 } } Procedures set f [open "| sort -rn" w] proc sum3 {a b c} { foreach word [array names count] { puts $f "$count($word) $word" return [expr $a + $b + $c] } } An Editable Graph An Editable Graph An Editable Graph # Set up the main window # Set up bottom control buttons set w .plot frame $w.buttons catch destroy $w pack $w.buttons -side bottom -fill x -pady 2m button $w.buttons.dismiss -text Dismiss -command "destroy $w" toplevel $w button $w.buttons.code -text "See Code" -command "showCode $w" wm title $w "Plot Demonstration" pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 wm iconname $w "Plot" positionWindow $w # Set up graph itself set c $w.c canvas $c -relief raised -width 450 -height 300 pack $w.c -side top -fill x # Text description at top # Draw axes label $w.msg -font $font -wraplength 4i -justify left \ set plotFont Helvetica 18 -text "This window displays a canvas widget containing $c create line 100 250 400 250 -width 2 a simple 2-dimensional plot. You can doctor the data $c create line 100 250 100 50 -width 2 by dragging any of the points with mouse button 1." $c create text 225 20 -text "A Simple Plot" -font $plotFont \ pack $w.msg -side top -fill brown An Editable Graph An Editable Graph Bourne Shell # Draw axis labels # Bind actions to events for {set i 0} {$i <= 10} {incr i} { $c bind point <Any-Enter> "$c itemconfig current -fill red" Default shell on most Unix systems (sh or bash). set x [expr {100 + ($i*30)}] $c bind point <Any-Leave> "$c itemconfig current -fill SkyBlue2" $c create line $x 250 $x 245 -width 2 $c bind point <1> "plotDown $c %x %y" Good for writing “shell scripts:” parsing command-line $c create text $x 254 -text [expr 10*$i] \ $c bind point <ButtonRelease-1> "$c dtag selected" -anchor n -font $plotFont bind $c <B1-Motion> "plotMove $c %x %y" arguments, invoking and controlling other commands, etc. } set plot(lastX) 0 for {set i 0} {$i <= 5} {incr i} { set plot(lastY) 0 set y [expr {250 - ($i*40)}] Example: The cc command. proc plotDown {w x y} { # Called when point clicked $c create line 100 $y 105 $y -width 2 global plot $c create text 96 $y -text [expr $i*50].0 \ $w dtag selected Most C compilers built from four pieces: -anchor e -font $plotFont $w addtag selected withtag current } $w raise current # Draw points set plot(lastX) $x Preprocessor (cpp) foreach point {{12 56} {20 94} {33 98} {32 120} {61 180} set plot(lastY) $y {75 160} {98 223}} { } Actual compiler (cc1) set x [expr {100 + (3*[lindex $point 0])}] proc plotMove {w x y} { # Called when point dragged set y [expr {250 - (4*[lindex $point 1])/5}] global plot set item [$c create oval [expr $x-6] [expr $y-6] \ $w move selected [expr $x-$plot(lastX)] \ Assembler (as) [expr $x+6] [expr $y+6] -width 1 -outline black \ [expr $y-$plot(lastY)] -fill SkyBlue2] set plot(lastX) $x $c addtag point withtag $item set plot(lastY) $y Linker (ld) } } cc in sh cc in sh cc in sh #!/bin/sh # Parse command-line options # Parse filenames while [ ! -z "$1" ]; while [ ! -z "$1" ]; do do case x"$1" in # Set up command names case x"$1" in x-v) echo "Stephen's cc 1.0"; exit 0 ;; root=/usr/lib x-o) shift; outfile=$1 ;; x*.c) cfiles="$cfiles $1" ;; cpp=$root/cpp x-c) stopafterassemble=1 ;; x*.s) sfiles="$sfiles
Recommended publications
  • Ajuba Solutions Version 1.4 COPYRIGHT Copyright © 1998-2000 Ajuba Solutions Inc
    • • • • • • Ajuba Solutions Version 1.4 COPYRIGHT Copyright © 1998-2000 Ajuba Solutions Inc. All rights reserved. Information in this document is subject to change without notice. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic or mechanical, including but not limited to photocopying or recording, for any purpose other than the purchaser’s personal use, without the express written permission of Ajuba Solutions Inc. Ajuba Solutions Inc. 2593 Coast Avenue Mountain View, CA 94043 U.S.A http://www.ajubasolutions.com TRADEMARKS TclPro and Ajuba Solutions are trademarks of Ajuba Solutions Inc. Other products and company names not owned by Ajuba Solutions Inc. that appear in this manual may be trademarks of their respective owners. ACKNOWLEDGEMENTS Michael McLennan is the primary developer of [incr Tcl] and [incr Tk]. Jim Ingham and Lee Bernhard handled the Macintosh and Windows ports of [incr Tcl] and [incr Tk]. Mark Ulferts is the primary developer of [incr Widgets], with other contributions from Sue Yockey, John Sigler, Bill Scott, Alfredo Jahn, Bret Schuhmacher, Tako Schotanus, and Kris Raney. Mark Diekhans and Karl Lehenbauer are the primary developers of Extended Tcl (TclX). Don Libes is the primary developer of Expect. TclPro Wrapper incorporates compression code from the Info-ZIP group. There are no extra charges or costs in TclPro due to the use of this code, and the original compression sources are freely available from http://www.cdrom.com/pub/infozip or ftp://ftp.cdrom.com/pub/infozip. NOTE: TclPro is packaged on this CD using Info-ZIP’s compression utility.
    [Show full text]
  • Introduction to Computer Systems 15-213/18-243, Spring 2009 1St
    M4-L3: Executables CSE351, Winter 2021 Executables CSE 351 Winter 2021 Instructor: Teaching Assistants: Mark Wyse Kyrie Dowling Catherine Guevara Ian Hsiao Jim Limprasert Armin Magness Allie Pfleger Cosmo Wang Ronald Widjaja http://xkcd.com/1790/ M4-L3: Executables CSE351, Winter 2021 Administrivia ❖ Lab 2 due Monday (2/8) ❖ hw12 due Friday ❖ hw13 due next Wednesday (2/10) ▪ Based on the next two lectures, longer than normal ❖ Remember: HW and readings due before lecture, at 11am PST on due date 2 M4-L3: Executables CSE351, Winter 2021 Roadmap C: Java: Memory & data car *c = malloc(sizeof(car)); Car c = new Car(); Integers & floats c->miles = 100; c.setMiles(100); x86 assembly c->gals = 17; c.setGals(17); Procedures & stacks float mpg = get_mpg(c); float mpg = Executables free(c); c.getMPG(); Arrays & structs Memory & caches Assembly get_mpg: Processes pushq %rbp language: movq %rsp, %rbp Virtual memory ... Memory allocation popq %rbp Java vs. C ret OS: Machine 0111010000011000 100011010000010000000010 code: 1000100111000010 110000011111101000011111 Computer system: 3 M4-L3: Executables CSE351, Winter 2021 Reading Review ❖ Terminology: ▪ CALL: compiler, assembler, linker, loader ▪ Object file: symbol table, relocation table ▪ Disassembly ▪ Multidimensional arrays, row-major ordering ▪ Multilevel arrays ❖ Questions from the Reading? ▪ also post to Ed post! 4 M4-L3: Executables CSE351, Winter 2021 Building an Executable from a C File ❖ Code in files p1.c p2.c ❖ Compile with command: gcc -Og p1.c p2.c -o p ▪ Put resulting machine code in
    [Show full text]
  • CERES Software Bulletin 95-12
    CERES Software Bulletin 95-12 Fortran 90 Linking Experiences, September 5, 1995 1.0 Purpose: To disseminate experience gained in the process of linking Fortran 90 software with library routines compiled under Fortran 77 compiler. 2.0 Originator: Lyle Ziegelmiller ([email protected]) 3.0 Description: One of the summer students, Julia Barsie, was working with a plot program which was written in f77. This program called routines from a graphics package known as NCAR, which is also written in f77. Everything was fine. The plot program was converted to f90, and a new version of the NCAR graphical package was released, which was written in f77. A problem arose when trying to link the new f90 version of the plot program with the new f77 release of NCAR; many undefined references were reported by the linker. This bulletin is intended to convey what was learned in the effort to accomplish this linking. The first step I took was to issue the "-dryrun" directive to the f77 compiler when using it to compile the original f77 plot program and the original NCAR graphics library. "- dryrun" causes the linker to produce an output detailing all the various libraries that it links with. Note that these libaries are in addition to the libaries you would select on the command line. For example, you might compile a program with erbelib, but the linker would have to link with librarie(s) that contain the definitions of sine or cosine. Anyway, it was my hypothesis that if everything compiled and linked with f77, then all the libraries must be contained in the output from the f77's "-dryrun" command.
    [Show full text]
  • Cygwin User's Guide
    Cygwin User’s Guide Cygwin User’s Guide ii Copyright © Cygwin authors Permission is granted to make and distribute verbatim copies of this documentation provided the copyright notice and this per- mission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this documentation under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this documentation into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. Cygwin User’s Guide iii Contents 1 Cygwin Overview 1 1.1 What is it? . .1 1.2 Quick Start Guide for those more experienced with Windows . .1 1.3 Quick Start Guide for those more experienced with UNIX . .1 1.4 Are the Cygwin tools free software? . .2 1.5 A brief history of the Cygwin project . .2 1.6 Highlights of Cygwin Functionality . .3 1.6.1 Introduction . .3 1.6.2 Permissions and Security . .3 1.6.3 File Access . .3 1.6.4 Text Mode vs. Binary Mode . .4 1.6.5 ANSI C Library . .4 1.6.6 Process Creation . .5 1.6.6.1 Problems with process creation . .5 1.6.7 Signals . .6 1.6.8 Sockets . .6 1.6.9 Select . .7 1.7 What’s new and what changed in Cygwin . .7 1.7.1 What’s new and what changed in 3.2 .
    [Show full text]
  • Scripting: Higher- Level Programming for the 21St Century
    . John K. Ousterhout Sun Microsystems Laboratories Scripting: Higher- Cybersquare Level Programming for the 21st Century Increases in computer speed and changes in the application mix are making scripting languages more and more important for the applications of the future. Scripting languages differ from system programming languages in that they are designed for “gluing” applications together. They use typeless approaches to achieve a higher level of programming and more rapid application development than system programming languages. or the past 15 years, a fundamental change has been ated with system programming languages and glued Foccurring in the way people write computer programs. together with scripting languages. However, several The change is a transition from system programming recent trends, such as faster machines, better script- languages such as C or C++ to scripting languages such ing languages, the increasing importance of graphical as Perl or Tcl. Although many people are participat- user interfaces (GUIs) and component architectures, ing in the change, few realize that the change is occur- and the growth of the Internet, have greatly expanded ring and even fewer know why it is happening. This the applicability of scripting languages. These trends article explains why scripting languages will handle will continue over the next decade, with more and many of the programming tasks in the next century more new applications written entirely in scripting better than system programming languages. languages and system programming
    [Show full text]
  • Ixia Tcl Development Guide
    Chapter 2: Quick Start 2 Installing the IxOS Tcl Client This chapter provides a quick means of getting started with the Tcl API. An example test is presented and explained. The IxOS Tcl Client provides an interface between an Ixia Tcl client application and Ixia IxOS Tcl functions. It runs on the Unix / Linux host. The Windows version of IxOS Tcl Client is included with the IxOS software package; the Unix/Linux version is supplied as a separate a self-extracting archive (.bin) file. You can download it from Ixia’s website, www.ixiacom.com. There are serveral versions of the IxOS Tcl Client. The correct file to install depends on the set up of the UNIX/Linux machine. Table 2-2 on page 2-1 details the files and their use. Table 2-2. Tcl Client Install Files Install File Purpose IxOS#.## For Linux versions post Redhat 9. It is distributed as genericLinux.bin a tarball (IxOS#.##genericLinux.bin.tar.gz) due to download issues. IxOS#.##linux.bin. For Linux platforms older than Redhat 9. IxOS#.##setup.jar An installer without a bundled Java Virtual Machine. This is distributed only to customers that have issues running the bin installers. It requires a Java Virtual Machine installed on the installation target. IxOS#.## For Solaris machines. solarisSparc.bin The versions of UNIX/Linux operating systems that are supported are: • Mandrake 7.2, RedHat 6.2, RedHat 7.0, RedHat 9.0 • RedHat Enterprise 4.0 IxOS Tcl Development Guide, 6.60 EA SP1 2-1 Quick Start 2 Installing the IxOS Tcl Client • Solaris 2.7 (7), 2.8 (8), 2.9 (9) Other versions of Linux and Solaris platforms may operate properly, but are not officially supported.
    [Show full text]
  • Automating Your Sync Testing
    APPLICATION NOTE By automating system verification and conformance testing to ITU-T synchronization standards, you’ll save on time and resources, and avoid potential test execution errors. This application note describes how you can use the Paragon-X’s Script Recorder to easily record Tcl, PERL and Python commands that can be integrated into your own test scripts for fast and efficient automated testing. AUTOMATING YOUR SYNC TESTING calnexsol.com Easily automate synchronization testing using the Paragon-X Fast and easy automation by Supports the key test languages Pre-prepared G.8262 Conformance recording GUI key presses Tcl, PERL and Python Scripts reduces test execution errors <Tcl> <PERL> <python> If you perform System Verification language you want to record i.e. Tcl, PERL SyncE CONFORMANCE TEST and Conformance Testing to ITU-T or Python, then select Start. synchronization standards on a regular Calnex provides Conformance Test Scripts basis, you’ll know that manual operation to ITU-T G.8262 for SyncE conformance of these tests can be time consuming, testing using the Paragon-X. These tedious and prone to operator error — as test scripts can also be easily tailored well as tying up much needed resources. and edited to meet your exact test Automation is the answer but very often requirements. This provides an easy means a lack of time and resource means it of getting your test automation up and remains on the ‘To do’ list. Now, with running and providing a repeatable means Calnex’s new Script Recorder feature, you of proving performance, primarily for ITU-T can get your automation up and running standards conformance.
    [Show full text]
  • Linking + Libraries
    LinkingLinking ● Last stage in building a program PRE- COMPILATION ASSEMBLY LINKING PROCESSING ● Combining separate code into one executable ● Linking done by the Linker ● ld in Unix ● a.k.a. “link-editor” or “loader” ● Often transparent (gcc can do it all for you) 1 LinkingLinking involves...involves... ● Combining several object modules (the .o files corresponding to .c files) into one file ● Resolving external references to variables and functions ● Producing an executable file (if no errors) file1.c file1.o file2.c gcc file2.o Linker Executable fileN.c fileN.o Header files External references 2 LinkingLinking withwith ExternalExternal ReferencesReferences file1.c file2.c int count; #include <stdio.h> void display(void); Compiler extern int count; int main(void) void display(void) { file1.o file2.o { count = 10; with placeholders printf(“%d”,count); display(); } return 0; Linker } ● file1.o has placeholder for display() ● file2.o has placeholder for count ● object modules are relocatable ● addresses are relative offsets from top of file 3 LibrariesLibraries ● Definition: ● a file containing functions that can be referenced externally by a C program ● Purpose: ● easy access to functions used repeatedly ● promote code modularity and re-use ● reduce source and executable file size 4 LibrariesLibraries ● Static (Archive) ● libname.a on Unix; name.lib on DOS/Windows ● Only modules with referenced code linked when compiling ● unlike .o files ● Linker copies function from library into executable file ● Update to library requires recompiling program 5 LibrariesLibraries ● Dynamic (Shared Object or Dynamic Link Library) ● libname.so on Unix; name.dll on DOS/Windows ● Referenced code not copied into executable ● Loaded in memory at run time ● Smaller executable size ● Can update library without recompiling program ● Drawback: slightly slower program startup 6 LibrariesLibraries ● Linking a static library libpepsi.a /* crave source file */ … gcc ..
    [Show full text]
  • Using the DLFM Package on the Cray XE6 System
    Using the DLFM Package on the Cray XE6 System Mike Davis, Cray Inc. Version 1.4 - October 2013 1.0: Introduction The DLFM package is a set of libraries and tools that can be applied to a dynamically-linked application, or an application that uses Python, to provide improved performance during the loading of dynamic libraries and importing of Python modules when running the application at large scale. Included in the DLFM package are: a set of wrapper functions that interface with the dynamic linker (ld.so) to cache the application's dynamic library load operations; and a custom libpython.so, with a set of optimized components, that caches the application's Python import operations. 2.0: Dynamic Linking and Python Importing Without DLFM When a dynamically-linked application is executed, the set of dependent libraries is loaded in sequence by ld.so prior to the transfer of control to the application's main function. This set of dependent libraries ordinarily numbers a dozen or so, but can number many more, depending on the needs of the application; their names and paths are given by the ldd(1) command. As ld.so processes each dependent library, it executes a series of system calls to find the library and make the library's contents available to the application. These include: fd = open (/path/to/dependent/library, O_RDONLY); read (fd, elfhdr, 832); // to get the library ELF header fstat (fd, &stbuf); // to get library attributes, such as size mmap (buf, length, prot, MAP_PRIVATE, fd, offset); // read text segment mmap (buf, length, prot, MAP_PRIVATE, fd, offset); // read data segment close (fd); The number of open() calls can be many times larger than the number of dependent libraries, because ld.so must search for each dependent library in multiple locations, as described on the ld.so(1) man page.
    [Show full text]
  • Building Performance Measurement Tools for the MINIX 3 Operating System
    Building Performance Measurement Tools for the MINIX 3 Operating System Rogier Meurs August 2006 Contents 1 INTRODUCTION 1 1.1 Measuring Performance 1 1.2 MINIX 3 2 2 STATISTICAL PROFILING 3 2.1 Introduction 3 2.2 In Search of a Timer 3 2.2.1 i8259 Timers 3 2.2.2 CMOS Real-Time Clock 3 2.3 High-level Description 4 2.4 Work Done in User-Space 5 2.4.1 The SPROFILE System Call 5 2.5 Work Done in Kernel-Space 5 2.5.1 The SPROF Kernel Call 5 2.5.2 Profiling using the CMOS Timer Interrupt 6 2.6 Work Done at the Application Level 7 2.6.1 Control Tool: profile 7 2.6.2 Analyzing Tool: sprofalyze.pl 7 2.7 What Can and What Cannot be Profiled 8 2.8 Profiling Results 8 2.8.1 High Scoring IPC Functions 8 2.8.2 Interrupt Delay 9 2.8.3 Profiling Runs on Simulator and Other CPU Models 12 2.9 Side-effect of Using the CMOS Clock 12 3 CALL PROFILING 13 3.1 Introduction 13 3.1.1 Compiler-supported Call Profiling 13 3.1.2 Call Paths, Call and Cycle Attribution 13 3.2 High-level Description 14 3.3 Work Done in User-Space 15 3.3.1 The CPROFILE System Call 15 3.4 Work Done in Kernel-Space 16 3.4.1 The PROFBUF and CPROF Kernel Calls 16 3.5 Work Done in Libraries 17 3.5.1 Profiling Using Library Functions 17 3.5.2 The Procentry Library Function 17 3.5.3 The Procexit Library Function 20 3.5.4 The Call Path String 22 3.5.5 Testing Overhead Elimination 23 3.6 Profiling Kernel-Space/User-Space Processes 24 3.6.1 Differences in Announcing and Table Sizes 24 3.6.2 Kernel-Space Issue: Reentrancy 26 3.6.3 Kernel-Space Issue: The Call Path 26 3.7 Work Done at the Application
    [Show full text]
  • Other Topics 1 Other Topics
    Other topics 1 Other topics 1 Other topics 15 Feb 2014 1 1.1 Description 1.1 Description Where to learn more about other topics that are useful for mod_perl developers and users. 1.2 Perl The Perl Documentation http://perldoc.perl.org/ The Perl Home Page http://www.perl.com/ The Perl Monks http://www.perlmonks.org/ What Perl Monks is: Our attempt to make learning Perl as nonintimidating and easy to use as possi- ble. A place for you and others to polish, improve, and showcase your Perl skills. A community which allows everyone to grow and learn from each other. The Perl Journal http://www.tpj.com/ The Perl Review http://theperlreview.com/ The Perl Review is a magazine for the Perl community by the Perl community produced with open source tools. CPAN - Comprehensive Perl Archive Network http://cpan.org and http://search.cpan.org/ Perl Module Mechanics http://world.std.com/~swmcd/steven/perl/module_mechanics.html - This page describes the mechan- ics of creating, compiling, releasing and maintaining Perl modules. Creating (and Maintaining) Perl Modules http://www.mathforum.com/~ken/perl_modules.html XS tutorials 2 15 Feb 2014 Other topics 1.3 Perl/CGI Perl manpages: perlguts, perlxs, and perlxstut manpages. Dean Roehrich’s XS CookBookA and CookBookB http://search.cpan.org/search?dist=CookBookA http://search.cpan.org/search?dist=CookBookB a series of articles by Steven McDougall: http://world.std.com/~swmcd/steven/perl/pm/xs/intro/index.html http://world.std.com/~swmcd/steven/perl/pm/xs/concepts.html http://world.std.com/~swmcd/steven/perl/pm/xs/tools/index.html http://world.std.com/~swmcd/steven/perl/pm/xs/modules/modules.html http://world.std.com/~swmcd/steven/perl/pm/xs/nw/NW.html Advanced Perl Programming By Sriram Srinivasan.
    [Show full text]
  • Environment Variable and Set-UID Program Lab 1
    SEED Labs – Environment Variable and Set-UID Program Lab 1 Environment Variable and Set-UID Program Lab Copyright © 2006 - 2016 Wenliang Du, All rights reserved. Free to use for non-commercial educational purposes. Commercial uses of the materials are prohibited. The SEED project was funded by multiple grants from the US National Science Foundation. 1 Overview The learning objective of this lab is for students to understand how environment variables affect program and system behaviors. Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. They are used by most operating systems, since they were introduced to Unix in 1979. Although environment variables affect program behaviors, how they achieve that is not well understood by many programmers. As a result, if a program uses environment variables, but the programmer does not know that they are used, the program may have vulnerabilities. In this lab, students will understand how environment variables work, how they are propagated from parent process to child, and how they affect system/program behaviors. We are particularly interested in how environment variables affect the behavior of Set-UID programs, which are usually privileged programs. This lab covers the following topics: • Environment variables • Set-UID programs • Securely invoke external programs • Capability leaking • Dynamic loader/linker Readings and videos. Detailed coverage of the Set-UID mechanism, environment variables, and their related security problems can be found in the following: • Chapters 1 and 2 of the SEED Book, Computer & Internet Security: A Hands-on Approach, 2nd Edition, by Wenliang Du.
    [Show full text]