Program That Runs Other Programs Unix/Linux Process Hierarchy Shell

Total Page:16

File Type:pdf, Size:1020Kb

Program That Runs Other Programs Unix/Linux Process Hierarchy Shell shell: program that runs other programs Building a Shell 1 5 Unix/Linux Process Hierarchy shell program that runs other programs on behalf of the user sh Original Unix shell (Stephen Bourne, AT&T Bell Labs, 1977) [0] bash “Bourne-Again” Shell, widely used default on most Unix/Linux/Mac OS X systems others.. init [1] while (true) { Print command prompt. Daemon Login shell Read command line from user. e.g. httpd Parse command line. If command is built-in, do it. Child Child Child Else fork process to execute command. in child: Execute requested command with execv. (never returns) Grandchild Grandchild in parent: Wait for child to complete. } 6 7 1 terminal ≠ shell Background vs. Foreground User interface to shell and other programs. Users generally run one command at a time Graphical (GUI) vs. command-line (CLI) Type command, read output, type another command Command-line terminal (emulator): Input (keyboard) Some programs run “for a long time” Output (screen) $ emacs fizz. txt # shell stuck until ema cs exi ts. A “background” job is a process we don't want to wait for $ emacs boom. txt & # em acs ru ns in backg round [1] 9073 # wh ile sh ell i s... $ gdb ./ umbre lla # im mediat ely r eady f or nex t com mand don't do this with emacs un l es s u si n g X wi nd o ws vers i o n 8 9 Managing Background Jobs Signals Signal: small message notifying a process of event in system Shell waits for and reaps foreground jobs. like exceptions and interrupts sent by kernel, sometimes at request of another process Background jobs become zombies when they terminate. ID is entire message Shell might run for a really long time! ID Name Corresponding Event Default Action Can Kernel may run out of memory! Override? fork() returns -1 if per-user process quota exceeded 2 SIGINT Interrupt (Ctrl-C) Te r m i n a t e Yes $ ul imi t -u # b ash sy nta x 9 SIGKILL Kill process (immediately) Te r m i n a t e No 1024 11 SIGSEGV Segmentation violation Te r m i n a t e & D u m p Yes 14 SIGALRM Timer signal Te r m i n a t e Yes Shell must explicitly reap background jobs. 15 SIGTERM Kill process (politely) Te r m i n a t e Yes One way: check/reap any completed background jobs before every prompt. 17 SIGCHLD Child stopped or terminated Ignore Yes OK, assuming foreground jobs/user inactivity are not too long. 18 SIGCONT Continue stopped process Continue (Resume) No Another way: OS delivers signal via exceptional control flow when child ends. 19 SIGSTOP Stop process (immediately) Stop (Suspend) No OK to respond by reaping, but complicated concurrency makes it tricky. 20 SIGTSTP Stop process (politely) Stop (Suspend) Yes 10 … 12 2 Sending/Receiving a Signal Signals Handlers as Concurrent Flows Kernel sends (delivers) a signal to a destination process by updating state in the context of the destination process. Signal handlers run concurrently with main program (in same process). Reasons: System event, e.g. segmentation fault (SIGSEGV) Another process used kill system call: explicitly request the kernel send a signal to the destination process Process A Process A Process B while (1) handler(){ Destination process receives signal when kernel forces it to react. ; … } Reactions: Ignore the signal (do nothing) Time Terminate the process (with optional core dump) Catch the signal by executing a user-level function called signal handler Like an impoverished Java exception handler 13 15 Another View of Signal Handlers as Pending and Blocked Signals Concurrent Flows A signal is pending if sent but not yet received <= 1 pending signal per type per process Process A Process B No Queue! Just a bit per signal type. Signals of type S discarded while process has S signal pending. Signal delivered Icurr user code (main) kernel code context switch A process can block the receipt of certain signals user code (main) Receipt delayed until the signal is unblocked kernel code context switch Signal received user code (handler) A pending signal is received at most once kernel code I next user code (main) Let's draw a picture... 16 17 3 Sending Signals from the Keyboard Process Groups Every process belongs to exactly one process group Shell: Ctrl-C sends SIGINT (Ctrl-Z sends SIGTSTP) to every job in the foreground process group. (default: parent's group) SIGINT – default action is to terminate each process pid=10 SIGTSTP – default action is to stop (suspend) each process pgid=10 Shell pid=10 pgid=10 Shell Fore- Bac k- Bac k- pid=20 pid=32 ground ground ground pid=40 pgid=20 pgid=32 pgid=40 job job #1 job #2 Fore- Bac k- Bac k- pid=20 pid=32 pid=40 pgid=20 ground ground ground Background pgid=32 pgid=40 Background job job #1 job #2 process group 32 process group 40 Child Child Background Background getp grp () process group 32 process group 40 pid=21 pid=22 Child Child pgid=20 pgid=20 Return process group of current process Foreground setp gid () pid=21 pid=22 process group 20 Change process group of a process pgid=20 pgid=20 Foreground process group 20 19 20 Signal demos A Program That Reacts to Ctrl-C Externally Generated Events (Ctrl-c) #include <stdlib.h> Ctrl-Z #include <stdio.h> #include <signal.h> void handler(int sig) { kill safe_printf("You think hitting ctrl-c will stop me?\n"); sleep(2); safe_printf("Well..."); > ./external kill(pid, SIGINT); sleep(1); <ctrl-c> printf(" O K \n"); You think hitting ctrl-c will stop me? exit(0); Well...OK } > main() { signal(SIGINT, handler); /* installs ct r l -c handler */ while(1) { } } external.c 21 32 4 A Program That Reacts to Internally Signal summary Generated Events Signals provide process-level exception handling #include <stdio.h> main() { Can generate from user programs #include <signal.h> signal(SIGALRM, handler); Can define effect by declaring signal handler alarm(1); /* send SIGALRM in int beeps = 0; 1 second */ Some caveats Very high overhead /* SIGALRM handler */ while (1) { void handler(int sig) { >10,000 clock cycles safe_printf("BEEP\n"); } } Only use for exceptional conditions if (++beeps < 5) Not queued alarm(1); > ./internal else { Just one bit for each pending signal type BEEP safe_printf("DING DING!\n"); BEEP Many more complicated details we have not discussed. exit(0); BEEP } Book goes into too much gory detail. BEEP } BEEP internal.c DING DING! > 33 42 5.
Recommended publications
  • Program #6: Word Count
    CSc 227 — Program Design and Development Spring 2014 (McCann) http://www.cs.arizona.edu/classes/cs227/spring14/ Program #6: Word Count Due Date: March 11 th, 2014, at 9:00 p.m. MST Overview: The UNIX operating system (and its variants, of which Linux is one) includes quite a few useful utility programs. One of those is wc, which is short for Word Count. The purpose of wc is to give users an easy way to determine the size of a text file in terms of the number of lines, words, and bytes it contains. (It can do a bit more, but that’s all of the functionality that we are concerned with for this assignment.) Counting lines is done by looking for “end of line” characters (\n (ASCII 10) for UNIX text files, or the pair \r\n (ASCII 13 and 10) for Windows/DOS text files). Counting words is also straight–forward: Any sequence of characters not interrupted by “whitespace” (spaces, tabs, end–of–line characters) is a word. Of course, whitespace characters are characters, and need to be counted as such. A problem with wc is that it generates a very minimal output format. Here’s an example of what wc produces on a Linux system when asked to count the content of a pair of files; we can do better! $ wc prog6a.dat prog6b.dat 2 6 38 prog6a.dat 32 321 1883 prog6b.dat 34 327 1921 total Assignment: Write a Java program (completely documented according to the class documentation guidelines, of course) that counts lines, words, and bytes (characters) of text files.
    [Show full text]
  • ENV-11 License Amendment
    CITY OF BURLINGTON ● DEPARTMENT OF PUBLIC WORKS ENV AMENDMENT TO SOLID WASTE LICENSE TO BE COMPLETED WHEN A VEHICLE FLEET CHANGES OR EARLY PICK UPS ARE REQUESTED PURSUANT TO CHAPTER 14, CODE OF ORDINANCES. (SEE INSTRUCTIONS ON BACK BEFORE COMPLETING) 11 IDENTIFICATION FEDERAL EIN ACCOUNT ID TRADE NAME (DBA, etc.) LEGAL NAME BUSINESS TELEPHONE NUMBER BUSINESS FAX NUMBER TAXPAYER REPRESENTATIVE YEARS IN BUSINESS FORM OF BUSINESS (check one) Sole Proprietorship Partnership/LLC Corporation BUSINESS ADDRESS CITY/TOWN STATE ZIP CODE CONTACT NAME CONTACT PHONE NUMBER CONTACT EMAIL ADDRESS AMENDMENT This is to amend the solid waste collection license for fiscal year 20____. EARLY PICK UPS Are you requesting early pick up? YES NO Are you requesting changes to an approved early pick up? YES NO Did you attach ENV-10B, Early Pick Up Requests? YES N/A CHANGES TO VEHICLE FLEET Has a vehicle been added to or removed from your fleet? YES NO Has the location of your parked vehicles changed? YES NO New Location: Did you attach ENV-10A, Vehicle Descriptions? YES N/A I certify that I have read the City of Burlington’s solid waste ordinance (Chapter 14, Burlington Code of Ordinances) and regulations. I understand that failure to observe the law and regulations could result in a revocation of my license to collect solid waste and recyclable material within the City of Burlington. I also certify that I understand the City of Burlington has a Noise Control Ordinance (Sec. 21-13, Code of Ordinances) and that I cannot begin the collection of solid waste or recyclable material before 7:00 a.m.
    [Show full text]
  • DC Console Using DC Console Application Design Software
    DC Console Using DC Console Application Design Software DC Console is easy-to-use, application design software developed specifically to work in conjunction with AML’s DC Suite. Create. Distribute. Collect. Every LDX10 handheld computer comes with DC Suite, which includes seven (7) pre-developed applications for common data collection tasks. Now LDX10 users can use DC Console to modify these applications, or create their own from scratch. AML 800.648.4452 Made in USA www.amltd.com Introduction This document briefly covers how to use DC Console and the features and settings. Be sure to read this document in its entirety before attempting to use AML’s DC Console with a DC Suite compatible device. What is the difference between an “App” and a “Suite”? “Apps” are single applications running on the device used to collect and store data. In most cases, multiple apps would be utilized to handle various operations. For example, the ‘Item_Quantity’ app is one of the most widely used apps and the most direct means to take a basic inventory count, it produces a data file showing what items are in stock, the relative quantities, and requires minimal input from the mobile worker(s). Other operations will require additional input, for example, if you also need to know the specific location for each item in inventory, the ‘Item_Lot_Quantity’ app would be a better fit. Apps can be used in a variety of ways and provide the LDX10 the flexibility to handle virtually any data collection operation. “Suite” files are simply collections of individual apps. Suite files allow you to easily manage and edit multiple apps from within a single ‘store-house’ file and provide an effortless means for device deployment.
    [Show full text]
  • UKUI: a Lightweight Desktop Environment Based on Pluggable
    2016 International Conference on Artificial Intelligence and Computer Science (AICS 2016) ISBN: 978-1-60595-411-0 UKUI: A Lightweight Desktop Environment Based on Pluggable Framework for Linux Distribution Jie YU1, Lu SI1,*, Jun MA1, Lei LUO1, Xiao-dong LIU1, Ya-ting KUANG2, Huan PENG2, Rui LI1, Jin-zhu KONG2 and Qing-bo WU1 1College of Computer, National University of Defense Technology, Changsha, China 2Tianjin KYLIN Information Technology Co., Ltd, Tianjin, China *[email protected] *Corresponding author Keywords: Desktop environment, Ubuntu, User interface. Abstract. Ubuntu is an operating system with Linux kernel based on Debian and distributed as free and open-source software. It uses Unity as its default desktop environment, which results in more difficulties of usage for Microsoft Windows users. In this paper, we present a lightweight desktop environment named UKUI based on UbuntuKylin, the official Chinese version of Ubuntu, for Linux distribution. It is designed as a pluggable framework and provides better user experience during human-computer interaction. In order to evaluate the performance of UKUI, a set of testing bench suits were performed on a personal computer. Overall, the results showed that UKUI has better performance compared with Unity. Introduction Linux is a freely available operating system (OS) originated by Linux Torvalds and further developed by thousands of others. Typically, Linux is packaged in a form known as a Linux distribution for both desktop and server use. Some of the most popular mainstream Linux distributions are Red Hat [1], Ubuntu [2], Arch [3], openSUSY [4], Gentoo [5], etc. There are several desktop environments available for nowadays modern Linux distributions, such as XFCE [6], GNOME [7], KDE [8] and LXDE [9].
    [Show full text]
  • Modern Programming Languages CS508 Virtual University of Pakistan
    Modern Programming Languages (CS508) VU Modern Programming Languages CS508 Virtual University of Pakistan Leaders in Education Technology 1 © Copyright Virtual University of Pakistan Modern Programming Languages (CS508) VU TABLE of CONTENTS Course Objectives...........................................................................................................................4 Introduction and Historical Background (Lecture 1-8)..............................................................5 Language Evaluation Criterion.....................................................................................................6 Language Evaluation Criterion...................................................................................................15 An Introduction to SNOBOL (Lecture 9-12).............................................................................32 Ada Programming Language: An Introduction (Lecture 13-17).............................................45 LISP Programming Language: An Introduction (Lecture 18-21)...........................................63 PROLOG - Programming in Logic (Lecture 22-26) .................................................................77 Java Programming Language (Lecture 27-30)..........................................................................92 C# Programming Language (Lecture 31-34) ...........................................................................111 PHP – Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)........................129 Modern Programming Languages-JavaScript
    [Show full text]
  • Shell Script & Advance Features of Shell Programming
    Kirti Kaushik et al, International Journal of Computer Science and Mobile Computing, Vol.4 Issue.4, April- 2015, pg. 458-462 Available Online at www.ijcsmc.com International Journal of Computer Science and Mobile Computing A Monthly Journal of Computer Science and Information Technology ISSN 2320–088X IJCSMC, Vol. 4, Issue. 4, April 2015, pg.458 – 462 RESEARCH ARTICLE Shell Script & Advance Features of Shell Programming Kirti Kaushik* Roll No.15903, CS, Department of Computer science, Dronacharya College of Engineering, Gurgaon-123506, India Email: [email protected] Jyoti Yadav Roll No. 15040, CS, Department of Applied Computer science, Dronacharya College of Engineering, Gurgaon-123506, India Email: [email protected] Kriti Bhatia Roll No. 15048, CS, Department of Applied Computer science, Dronacharya College of Engineering, Gurgaon-123506, India Email: [email protected] Abstract-- In this research paper, the idea of shell scripting and writing computer programs is examined and different parts of shell programming are likewise contemplated. A shell script is a PC system intended to be controlled by the UNIX shell which is a charge line translator. The different tongues of shell scripts are thought to be scripting dialects. Regular operations performed by shell scripts incorporate document control, program execution, and printing content. A shell script can give an advantageous variety ofa framework order where unique environment settings, charge alternatives, or post-transforming apply naturally, yet in a manner that permits the new script to still go about as a completely typical UNIX summon. The real ideas like Programming in the Borne and C-shell, in which it would be clarified that how shell programming could be possible in Borne and C-shell.
    [Show full text]
  • Openvms Security
    OpenVMS Security Presented by Paul Williams PARSEC Group 999 18th Street, Suite 1725 Denver, CO 80202 www.parsec.com | 888-4-PARSEC To Download this Presentation, please visit: http://www.parsec.com/public/openvmssecurity.pdf To E-mail Paul [email protected] www.parsec.com | 888-4-PARSEC Outline • OpenVMS Security Design • Physical Security • Object Security • UIC/ACL Security • User Access • Break-in Detection • Network and Internet Considerations • Encrypted Network Communication • Kerberos • Secure Socket Layer (SSL) Goals • Discuss the important points and consideration of OpenVMS Security • Concentrate on the mechanics and mechanisms of OpenVMS features. • Show how OpenVMS is one of the most secure operating systems on the market. OpenVMS Security Design • Security was designed into OpenVMS since V1.0 • Many different levels of security in OpenVMS Physical Security Object Security User Management Network Security • Has never had a virus Physical Security • System • System Console • Storage devices and media System Disk Data and Database Volumes Backups • Network devices and media Physical Security: System • Increase system reliability through restricted access Prevent intentional tampering and outage Prevent outage due to accidents • Prevent Front Panel Access Halts Reset/initializations Power switch/source Power on action settings (VAX) switch Physical Security: Console • Can be a big security hole for OpenVMS Anyone with physical access to the console can break into OpenVMS buy getting into the SYSBOOT utility. Then OpenVMS can be broken into: Buy redirecting startup Buy changing system parameters Physical Security: Getting to SYSBOOT on the Integrity Console Example • On the Integrity shutdown to the EFI Boot Manager and select the EFI Shell and create a alias.
    [Show full text]
  • Praat Scripting Tutorial
    Praat Scripting Tutorial Eleanor Chodroff Newcastle University July 2019 Praat Acoustic analysis program Best known for its ability to: Visualize, label, and segment audio files Perform spectral and temporal analyses Synthesize and manipulate speech Praat Scripting Praat: not only a program, but also a language Why do I want to know Praat the language? AUTOMATE ALL THE THINGS Praat Scripting Why can’t I just modify others’ scripts? Honestly: power, flexibility, control Insert: all the gifs of ‘you can do it’ and ‘you got this’ and thumbs up Praat Scripting Goals ~*~Script first for yourself, then for others~*~ • Write Praat scripts quickly, effectively, and “from scratch” • Learn syntax and structure of the language • Handle various input/output combinations Tutorial Overview 1) Praat: Big Picture 2) Getting started 3) Basic syntax 4) Script types + Practice • Wav files • Measurements • TextGrids • Other? Praat: Big Picture 1) Similar to other languages you may (or may not) have used before • String and numeric variables • For-loops, if else statements, while loops • Regular expression matching • Interpreted language (not compiled) Praat: Big Picture 2) Almost everything is a mouse click! i.e., Praat is a GUI scripting language GUI = Graphical User Interface, i.e., the Objects window If you ever get lost while writing a Praat script, click through the steps using the GUI Getting Started Open a Praat script From the toolbar, select Praat à New Praat script Save immediately! Save frequently! Script Goals and Input/Output • Consider what
    [Show full text]
  • What Is the Shell? • the Login Shell
    03 0672324903 Ch03 2/3/03 1:41 PM Page 41 3 IN THIS CHAPTER • The Kernel and the Utilities What Is the Shell? • The Login Shell • Typing Commands to the Shell In this chapter you’ll learn what the shell is and what it does. • The Shell’s Responsibilities The Kernel and the Utilities The Unix system is itself logically divided into two pieces: the kernel and the utilities (see Figure 3.1). Unix system Utilities kernel disks Memory FIGURE 3.1 The Unix system. The kernel is the heart of the Unix system and resides in the computer’s memory from the time the computer is turned on and booted until the time it is shut down. The utilities, on the other hand, reside on the computer’s disk and are only brought into memory as requested. Virtually every command you know under the Unix system is classified as a utility; therefore, the program resides on the disk and is brought into memory only when you request that the command be executed. So, for example, when you execute the date command, the Unix system loads the program called date from the computer’s disk into memory and initiates its execution. The shell, too, is a utility program. It is loaded into memory for execution whenever you log in to the system. 03 0672324903 Ch03 2/3/03 1:41 PM Page 42 42 CHAPTER 3 What Is the Shell? In fact, it’s worth learning the precise sequence of events that occurs when the first shell on a terminal or window starts up.
    [Show full text]
  • Mac OS X: an Introduction for Support Providers
    Mac OS X: An Introduction for Support Providers Course Information Purpose of Course Mac OS X is the next-generation Macintosh operating system, utilizing a highly robust UNIX core with a brand new simplified user experience. It is the first successful attempt to provide a fully-functional graphical user experience in such an implementation without requiring the user to know or understand UNIX. This course is designed to provide a theoretical foundation for support providers seeking to provide user support for Mac OS X. It assumes the student has performed this role for Mac OS 9, and seeks to ground the student in Mac OS X using Mac OS 9 terms and concepts. Author: Robert Dorsett, manager, AppleCare Product Training & Readiness. Module Length: 2 hours Audience: Phone support, Apple Solutions Experts, Service Providers. Prerequisites: Experience supporting Mac OS 9 Course map: Operating Systems 101 Mac OS 9 and Cooperative Multitasking Mac OS X: Pre-emptive Multitasking and Protected Memory. Mac OS X: Symmetric Multiprocessing Components of Mac OS X The Layered Approach Darwin Core Services Graphics Services Application Environments Aqua Useful Mac OS X Jargon Bundles Frameworks Umbrella Frameworks Mac OS X Installation Initialization Options Installation Options Version 1.0 Copyright © 2001 by Apple Computer, Inc. All Rights Reserved. 1 Startup Keys Mac OS X Setup Assistant Mac OS 9 and Classic Standard Directory Names Quick Answers: Where do my __________ go? More Directory Names A Word on Paths Security UNIX and security Multiple user implementation Root Old Stuff in New Terms INITs in Mac OS X Fonts FKEYs Printing from Mac OS X Disk First Aid and Drive Setup Startup Items Mac OS 9 Control Panels and Functionality mapped to Mac OS X New Stuff to Check Out Review Questions Review Answers Further Reading Change history: 3/19/01: Removed comment about UFS volumes not being selectable by Startup Disk.
    [Show full text]
  • SUSE® Linux Enterprise Desktop 12 and the Workstation Extension: What's New ?
    SUSE® Linux Enterprise Desktop 12 and the Workstation Extension: What's New ? Frédéric Crozat <[email protected]> Enterprise Desktop Release Manager Scott Reeves <[email protected]> Enterprise Desktop Development Manager Agenda • Design Criteria • Desktop Environment in SUSE Linux Enterprise 12 • GNOME Shell • Desktop Features and Applications 2 Design Criteria SUSE Linux Enterprise Desktop Interoperability Ease of Use Security Ease of Management Lower Costs 4 SUSE Linux Enterprise Desktop 12 • Focus on technical workstation ‒ Developers and System administrators • One tool for the job • Main desktop applications will be shipped: ‒ Mail client, Office Suite, Graphical Editors, ... • SUSE Linux Enterprise Workstation Extension ‒ Extend SUSE Linux Enterprise Server with packages only available on SUSE Linux Enterprise Desktop. (x86-64 only) 5 Desktop in SUSE Linux Enterprise 12 As Part of the Common Code Base SUSE Linux Enterprise 12 Desktop Environment • SUSE Linux Enterprise 12 contains one primary desktop environment • Additional light-weight environment for special use-cases: ‒ Integrated Systems • Desktop environment is shared between the server and desktop products 7 SUSE Linux Enterprise 12 Desktop Environment • GNOME 3 is the main desktop environment ‒ SLE Classic mode by default ‒ GNOME 3 Classic Mode and GNOME 3 Shell Mode also available • SUSE Linux Enterprise 12 ships also lightweight IceWM ‒ Targeted at Integrated Systems • QT fully supported: ‒ QT5 supported for entire SLE12 lifecycle ‒ QT4 supported, will be removed in future
    [Show full text]
  • Unique Identifier for Staff (UID Staff) Overview
    Unique Identifier for Staff (UID Staff) Overview The intent of this document is to provide an overview of the Unique Identifier for Staff (UID Staff) system prior to working in the UID Staff System. After reviewing this information, please review the training materials that are available on the UID Staff Training website (http://www.ncpublicschools.org/cedars/uniqueid/staff/training/) for instructions on how to complete the processes of the Staff UID System. Staff UID Overview • The Unique Identifier for Staff System (UID Staff) will assign a unique identifier to Staff who participate in the North Carolina public school system. • Unique IDs follow staff between school districts and remain valid even if they move out of state and then return to a NC public school. • Assigning unique identifiers is the first step in DPI’s multi-stage effort to create the NC Common Education Data Analysis and Reporting System (CEDARS). • UID Staff is built on the eScholar Uniq-ID® for Staff product. Overview of UID Staff Process The UID Staff process includes the following 8 steps: 1. Generate CEDARS Staff file from LEA/Charter School Payroll System • Instructions for generating this file can be found at: http://www.ncpublicschools.org/docs/cedars/uniqueid/staff/training/creating-extracts.pdf 2. Upload CEDARS Staff file into UID Staff and Initiates Data Validation • This file can be loaded into the Training Environment (https://cedarstrain.schools.nc.gov/staffid/) so that you can check for errors before loading into production. 3. Download Fix Errors Report (if data errors are found by the UID Staff System) 4.
    [Show full text]