Systems Programming/ C and UNIX

Total Page:16

File Type:pdf, Size:1020Kb

Systems Programming/ C and UNIX Systems Programming/ C and UNIX Alice E. Fischer November, 2017 Alice E. Fischer Systems Programming { Lecture 10. 1/8 November, 2017 1 / 8 Outline 1 Jobs and Job Control 2 Foreground, Background, and Suspension 3 Detached Processes Alice E. Fischer Systems Programming { Lecture 10. 2/8 November, 2017 2 / 8 Jobs and Job Control A Job is a Process. We use the term job to refer to a process that is controlled by a shell. Once started, each job is either in the foreground, running in the background, or suspended. Starting a job the normal way puts it in the foreground: ∼> server2 To start a job in the background, use an ampersand: ∼> server2 & The shell will start the background job, then return immediately to you so that you can start another job that will run concurrently. The output from the background job will still come to the terminal screen. To suspend the foreground process, type ^Z The suspended job will stop running, but can be restarted. To resume a job after suspension, type ps to find its job number, n then type fg %n or bg %n If you start a job in the background, your shell will control it. Alice E. Fischer Systems Programming { Lecture 10. 3/8 November, 2017 3 / 8 Jobs and Job Control Job Control: server2 and the three clients To prepare for this experiment, I used a shell to start the server: ∼> server2 I opened a second shell and listed the jobs it was controlling: ∼> jobs The list was empty. Then I used the same shell to start three clients at the same time, all running in the background ∼> clientM localhost & clientJ localhost & client & Typing jobs again for this shell, we see: ∼> jobs [1] + Running clientJ localhost [2] - Running clientM localhost [3] Running client localhost Alice E. Fischer Systems Programming { Lecture 10. 4/8 November, 2017 4 / 8 Foreground, Background, and Suspension Foreground, Background, and Suspension You can only send keyboard input to a foreground job. You can suspend both foreground and background jobs. To move job [2] into the foreground, use: ∼> fg %2 Control-Z suspends the foreground job and returns control to the shell. After suspending clientM we see: ∼> jobs [1] + Running clientJ localhost [2] - Suspended clientM localhost [3] Running client localhost To resume work on job [2] in the background or in the foreground use: ∼> bg %2 or ∼> fg %2 Alice E. Fischer Systems Programming { Lecture 10. 5/8 November, 2017 5 / 8 Foreground, Background, and Suspension Foreground and Background A \+" in the list of jobs marks the current \default" job. If a fg or bg command is given without a job number, it affects the default job. A \-" in the list of jobs marks the prior-current job. You can manage this job using %- Output to stdout from all of the running jobs will come to the shell unless stdout was redirected when the job was started. If the shell is in the foreground, and a background job has produced some output, hit return to get a command prompt. Suppose one of your running background jobs ends with a fatal error and is waiting for you to release it. You must bring it to the foreground, then release it. It will then exit and be gone from the jobs list. Alice E. Fischer Systems Programming { Lecture 10. 6/8 November, 2017 6 / 8 Detached Processes Detached Processes We use a shell to run and control processes. Usually, this is a simple matter; but things can get complex. Suppose your shell is running a job in the background, and it is not suspended. When you close the shell window, that terminates the shell and its foreground process. But it does not terminate a running background process. That process lives on as a detached process. If it is a server, new clients can still attach to it. This can create a mess! To see the detached process, use another shell to type ps a To terminate it gracefully, use kill pid or kill -TERM pid To terminate it immediately, use kill -KILL pid . Alice E. Fischer Systems Programming { Lecture 10. 7/8 November, 2017 7 / 8 Detached Processes Recovering from a Mess Suppose you have made a mess Several jobs are controlled by your shell, Suppose one of them needs to be stopped because it is out of control and not responding to normal signals. You could stop all of the controlled processes by killing the shell. However, this may be a bad idea, because a process running in the background becomes detached when you close its shell. It is like a daemon! If you only want to stop one job, use the kill command. Kill it this way from the same shell window: ∼> kill -KILL %2 Kill it this way from a different shell window: ∼> ps and note the PID in the left-hand column. ∼> kill -KILL 48283 using that pid. Alice E. Fischer Systems Programming { Lecture 10. 8/8 November, 2017 8 / 8.
Recommended publications
  • Chapter 3: Processes
    Chapter 3: Processes Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server Systems Operating System Concepts – 9th Edition 3.2 Silberschatz, Galvin and Gagne ©2013 Objectives To introduce the notion of a process -- a program in execution, which forms the basis of all computation To describe the various features of processes, including scheduling, creation and termination, and communication To explore interprocess communication using shared memory and message passing To describe communication in client-server systems Operating System Concepts – 9th Edition 3.3 Silberschatz, Galvin and Gagne ©2013 Process Concept An operating system executes a variety of programs: Batch system – jobs Time-shared systems – user programs or tasks Textbook uses the terms job and process almost interchangeably Process – a program in execution; process execution must progress in sequential fashion Multiple parts The program code, also called text section Current activity including program counter, processor registers Stack containing temporary data Function parameters, return addresses, local variables Data section containing global variables Heap containing memory dynamically allocated during run time Operating System Concepts – 9th Edition 3.4 Silberschatz, Galvin and Gagne ©2013 Process Concept (Cont.) Program is passive entity stored on disk (executable
    [Show full text]
  • Unix / Linux Processes Management
    UUNNIIXX // LLIINNUUXX -- PPRROOCCEESSSSEESS MMAANNAAGGEEMMEENNTT http://www.tutorialspoint.com/unix/unix-processes.htm Copyright © tutorialspoint.com Advertisements In this chapter, we will discuss in detail about process management in Unix. When you execute a program on your Unix system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system. Whenever you issue a command in Unix, it creates, or starts, a new process. When you tried out the ls command to list the directory contents, you started a process. A process, in simple terms, is an instance of a running program. The operating system tracks processes through a five-digit ID number known as the pid or the process ID. Each process in the system has a unique pid. Pids eventually repeat because all the possible numbers are used up and the next pid rolls or starts over. At any point of time, no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process. Starting a Process When you start a process (run a command), there are two ways you can run it − Foreground Processes Background Processes Foreground Processes By default, every process that you start runs in the foreground. It gets its input from the keyboard and sends its output to the screen. You can see this happen with the ls command. If you wish to list all the files in your current directory, you can use the following command − $ls ch*.doc This would display all the files, the names of which start with ch and end with .doc − ch01-1.doc ch010.doc ch02.doc ch03-2.doc ch04-1.doc ch040.doc ch05.doc ch06-2.doc ch01-2.doc ch02-1.doc The process runs in the foreground, the output is directed to my screen, and if the ls command wants any input (which it does not), it waits for it from the keyboard.
    [Show full text]
  • Secrets of Powershell Remoting
    Secrets of PowerShell Remoting The DevOps Collective, Inc. This book is for sale at http://leanpub.com/secretsofpowershellremoting This version was published on 2018-10-28 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. © 2016 - 2018 The DevOps Collective, Inc. Also By The DevOps Collective, Inc. Creating HTML Reports in Windows PowerShell A Unix Person’s Guide to PowerShell The Big Book of PowerShell Error Handling DevOps: The Ops Perspective Ditch Excel: Making Historical and Trend Reports in PowerShell The Big Book of PowerShell Gotchas The Monad Manifesto, Annotated Why PowerShell? Windows PowerShell Networking Guide The PowerShell + DevOps Global Summit Manual for Summiteers Why PowerShell? (Spanish) Secrets of PowerShell Remoting (Spanish) DevOps: The Ops Perspective (Spanish) The Monad Manifesto: Annotated (Spanish) Creating HTML Reports in PowerShell (Spanish) The Big Book of PowerShell Gotchas (Spanish) The Big Book of PowerShell Error Handling (Spanish) DevOps: WTF? PowerShell.org: History of a Community Contents Secrets of PowerShell Remoting ..................................... 1 Remoting Basics ................................................ 3 What is Remoting? ............................................ 3 Examining Remoting Architecture .................................. 3 Enabling
    [Show full text]
  • Shells and Processes
    Shells and Processes Bryce Boe 2012/08/08 CS32, Summer 2012 B Outline • Operang Systems and Linux Review • Shells • Project 1 Part 1 Overview • Processes • Overview For Monday (Sor>ng Presentaons) OS Review • Operang systems – Manages system resources: cpu, memory, I/O – Types: single/mul>-user and single/mul>-process – Provides Fairness, security Self Check Quesons • What is the primary benefit oF a mul>-process OS over a single process OS? How is this accomplished? • Explain the difference between mul>programming and mul>tasking Self Check Answers • What is the primary benefit oF a mul>-process OS over a single process OS? How is this accomplished? – Increased resource u>lizaon (primarily oF the CPU) accomplished by scheduling other processes when the currently running process requires I/O SelF Check Answers cont. • Explain the difference between mul>programming and mul>tasking – Mul>programming systems switch the running process when that process requires I/O. – Mul>tasking systems periodically switch the running process aer some (typically minute) period of me Linux Architecture Shells What is a shell? • A shell is a program that provides the interFace between the user and the operang system • Can be used to tell the OS to: – Execute programs (as processes) – Stop, or pause processes – Create, copy, move, remove files – Load or unload device drivers Types of Shells • Command line shells: – Provide a textual input as the user-interFace – Bourne shell (sh), C shell (csh), Bourne-Again shell (bash), cmd.exe • Graphical shells – Provide a point-and-click
    [Show full text]
  • Operating Systems Basics • IOS Architecture Overview • Memory Organization • IOS Processes • IOS Kernel • Packet Buffer Management • Device Drivers
    Ch01i.book Page 2 Tuesday, June 13, 2000 2:43 PM This chapter covers the following key topics: • Operating Systems Basics • IOS Architecture Overview • Memory Organization • IOS Processes • IOS Kernel • Packet Buffer Management • Device Drivers Ch01i.book Page 3 Tuesday, June 13, 2000 2:43 PM C H A P T E R 1 Fundamental IOS Software Architecture If you were naming the most popular and widely used computer operating systems, which ones would you choose? Most likely, your list would contain names like UNIX, MS-DOS, Microsoft Windows, or even IBM’s MVS for mainframes. These are all well-known operating systems—you might even be using one on a computer at home. Now, think for a minute; are there any others? Would your list contain Cisco IOS? No, it probably wouldn’t, even though IOS is one of the most widely deployed operating systems in use today. Unlike the general-purpose operating systems just mentioned, many people never encounter IOS directly. Most who use a computer to access the Internet aren’t even aware IOS is behind the scenes. Even those who are aware of IOS, people who use it directly, often don’t consider it to be an operating system but instead just the software that runs Cisco routers. IOS might not run word processors or accounting applications like others on the list but it is still, in fact, an operating system—albeit, one specialized for switching data packets. As you will see, much of the IOS architecture is focused on switching packets as quickly and efficiently as possible.
    [Show full text]
  • Running a Script Without User Intervention 7
    ,ch02.2190 Page 6 Thursday, April 8, 2004 11:55 AM 2 Chapter 2 Running a Script Without User Intervention 2. We have indicated that scripts can be used to save huge amounts of time by carry- ing out mundane maintenance and configuration tasks automatically. However, it should be pointed out that no matter how sophisticated a script may be, it is never anything more than a text file containing words and symbols that can be under- stood by an interpreter. It is completely powerless to carry out any activities on a workstation unless explicitly executed. If you happen to be sitting in front of a workstation, running a script is trivial: it usually involves typing its name at the command prompt. While it might sound rather painless on the face of it, this inter- active method of running a script is completely impractical if you are attempting to look after a large number of workstations. The reason is simple: visiting each workstation in turn is the time-consuming activity. Unless the maintenance or con- figuration you intend to carry out is extremely complicated, it is likely to take very little additional effort to carry out the task manually. Unfortunately, there is no easy way to start a script remotely short of running a Telnet server on every workstation under your control (and there are many good reasons not to do this). Thankfully, however, there are ways of preinstalling scripts so that they run themselves either at predetermined times or in response to a workstation state. The significance of this is that a maintenance script designed to run regularly has to be installed only once and will require no further interven- tion; a configuration script can be preinstalled and primed so that it will start up by itself when required.
    [Show full text]
  • WIRELURKER: a New Era in Ios and OS X Malware
    WIRELURKER: A New Era in iOS and OS X Malware REPORT BY CLAUD XIAO PALO ALTO NETWORKS | 4401 Great America Parkway | Santa Clara, CA 95054 www.paloaltonetworks.com TABLE OF CONTENTS Executive Summary 3 Background 4 User Reporting for this Threat 4 Investigation of the Third Party App Store 5 WireLurker Workflow and Malware Progression 6 WireLurker Versions 7 Analysis of WireLurker OS X Malware 9 Bundle Repackaging and File Hiding 9 Self Update 11 Persistence Mechanisms 13 C2 Server Communication 14 iOS Application Download 15 USB Connection Monitoring 17 Exfiltration of Device Information 17 Installation of Malicious Dynamic Library to an iOS Device 18 Backup of Specific Installed Applications from an iOS Device 19 Trojanizing iOS Applications 20 Installation of Trojanized iOS Applications 20 Analysis of WireLurker iOS Malware 22 Code Injection into System Applications 22 Self Update 23 Exfiltration of User Data 24 Exfiltration of Application Usage and Device Serial Number Information 25 Overall Threat Analysis 26 Use of Repackaging to Trojanize Applications 26 Malicious Use of USB Connections 26 Attacks Against Jailbroken Devices 26 Attacks Against Non-Jailbroken Devices 26 Actor Motivation 27 Prevention, Detection, Containment and Remediation 27 Prevention 27 Detection and Containment 28 Remediation 29 Acknowledgements 29 Appendix 30 SHA-1 Hashes of WireLurker Related Files 30 URLs for C2 Communication 31 Version C Encrypted C2 Communication Code 32 Executive Summary Palo Alto Networks® recently discovered a new family of Apple OS X
    [Show full text]
  • Lecture 2 General Concepts of RTOS (Real-Time Operating System)
    CENG 383 Real-Time Systems Lecture 2 General Concepts of RTOS (Real-Time Operating System) Asst. Prof. Tolga Ayav, Ph.D. Department of Computer Engineering İzmir Institute of Technology Operating System z Specialized collection of system programs is called operating system. z Must provide at least three specific functions: − Task scheduling − Task dispatching − İntertask communication z Kernel (Nucleus): The smallest portion of OS that provides those three essential functions. İzmir Institute of Technology Embedded Systems Lab Role of the Kernel İzmir Institute of Technology Embedded Systems Lab Three Kernel Functions OS Kernel - 3 functions: z Task Scheduler : To determine which task will run next in a multitasking system z Task Dispatcher: To perform necessary bookkeeping to start a task z Intertask Communication: To support communication between one process (i.e. task) and another İzmir Institute of Technology Embedded Systems Lab Kernel Design Strategies z Polled Loop Systems z Cyclic Executive z Cooperative Multitasking z Interrupt-Driven Systems z Foreground/Background Systems z Full featured RTOS İzmir Institute of Technology Embedded Systems Lab 1. Polled Loop Systems Polled loops are used for fast response to single devices. In a polled-loop system, a single and a repetitive instruction is used to test a flag that indicates whether or not some event has occurred. If the event has not occurred, then the polling continues. Example: suppose a software system is needed to handle packets of data that arrive at a rate of no more than 1 per second. A flag named packet_here is set by the network, which writes the data into the CPU’s memory via direct memory access (DMA).
    [Show full text]
  • Processes in Linux/Unix
    Processes in Linux/Unix A program/command when executed, a special instance is provided by the system to the process. This instance consists of all the services/resources that may be utilized by the process under execution. • Whenever a command is issued in unix/linux, it creates/starts a new process. For example, pwd when issued which is used to list the current directory location the user is in, a process starts. • Through a 5 digit ID number unix/linux keeps account of the processes, this number is call process id or pid. Each process in the system has a unique pid. • Used up pid’s can be used in again for a newer process since all the possible combinations are used. • At any point of time, no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process. Initializing a process A process can be run in two ways: 1. Foreground Process : Every process when started runs in foreground by default, receives input from the keyboard and sends output to the screen. When issuing pwd command $ ls pwd Output: $ /home/geeksforgeeks/root When a command/process is running in the foreground and is taking a lot of time, no other processes can be run or started because the prompt would not be available until the program finishes processing and comes out. 2. Backround Process : It runs in the background without keyboard input and waits till keyboard input is required. Thus, other processes can be done in parallel with the process running in background since they do not have to wait for the previous process to be completed.
    [Show full text]
  • WE3-41 415 Proceedings of the 1988 Linear Accelerator Conference, Williamsburg, Virginia, USA
    Proceedings of the 1988 Linear Accelerator Conference, Williamsburg, Virginia, USA CEBAF CONTROL SYSTEM R. Bork, C. Grubb, G. Lahti, E. Navarro, J. Sage Continuous Electron Beam Accelerator Facility* 12000 Jefferson Avenue, Newport News, Virginia 23606 T. Moore Lawrence Livermore National Laboratory P.O. Box 808 Livermore, CA 94550 Abstract section is used to develop the internal data manipulations and control algorithms. A logic-based computer control system is in development at CEBAF. This Unix/C language software package, running The interface section development screen is a menu-driven on a distributed, hierarchical system of workstation and su­ development page used to define CAMAC and LAN interfaces pervisory minicomputers, interfaces to hardware via CAMAC. for the database. Among the capabilities of this section are: Software aspects to be covered are ladder logic, interactive 1) Adding/deleting computers. In a distributed process database generation, networking, and graphic user interfaces. scheme, computers may be added or deleted from the data­ base with necessary addresses and locations defined. Introduction 2) Adding/deleting CAMAC crates. A logic-based application software package, Thaumaturgic Automated Control Logic (TACL), is presently in development 3) Adding/deleting/moving CAMAC modules. at CEBAF for the control of machine operations. TACL is a 4) Defining I/O points. User-specified names are assigned to tool for building custom control software for a hierarchical, dis­ I/O channels to/from CAMAC modules and LAN. tributed process control system. It is premised on a ladder-logic configuration, with a series of editors for relational database 5) Maintaining the CAMAC module library. The library func­ generation.
    [Show full text]
  • Project Shell 2 Due: November 6, 2019 at 11:59Pm
    CSCI0330 Intro Computer Systems Doeppner Project Shell 2 Due: November 6, 2019 at 11:59pm 1 Introduction 2 Before you write any code, read this handout in its entirety. 2 2 Assignment 2 2.1 Stencil 2 2.2 Jobs vs. Processes 3 2.3 Foreground vs. Background 3 2.4 Specifications 3 3 Signals 5 3.0 Sending Signals 6 3.1 Ignoring Signals 6 3.2 Signal Handling in the Child Process 6 3.3 Process Groups 6 4 Multiple Jobs 7 4.1 Process State 8 5 Reaping 8 5.1 Reaping a Child Process 9 6 fg and bg 10 7 Support Code 10 8 Library Functions 12 9 Testing Your Shell 12 9.1 Format of the Tracefiles 13 9.2 Test Executables 13 9.3 Demo 13 9.4 Error Checking 13 9.5 Shell Clean Up 13 10 GDB Tips for Shell 2 14 10.1 handle signal 14 10.2 catch signal 14 11 Grading 14 1 CSCI0330 Project Shell 2 October 31, 2018 12 Handing In 14 1 Introduction Tom was drifting through the water with his new chum the magic conch. Suddenly, an enormous tentacle emerged from the depths of the ocean and speared into the heart of his friend, splitting the shell evenly in two. Tom was otterly overwhelmed with emocean and blinked mildly, looking at his friends, shell_1 and shell_2. Shell_2 was trying to communicate, but Tom couldn’t quite catch the signals. Kelp Tom reestablish connection with his shelly friends. CTRL-\. Now, your shell can run only one program at a time since it runs programs in the foreground, occupying the entire shell.
    [Show full text]
  • Paul Collins Status Name/Startup Item Command Comments X System32
    SYSINFO.ORG STARTUP LIST : 11th June 2006 (c) Paul Collins Status Name/Startup Item Command Comments X system32.exe Added by the AGOBOT-KU WORM! Note - has a blank entry under the Startup Item/Name field X pathex.exe Added by the MKMOOSE-A WORM! X svchost.exe Added by the DELF-UX TROJAN! Note - this is not the legitimate svchost.exe process which is always located in the System (9x/Me) or System32 (NT/2K/XP) folder and should not normally figure in Msconfig/Startup! This file is located in the Winnt or Windows folder X SystemBoot services.exe Added by the SOBER-Q TROJAN! Note - this is not the legitimate services.exe process which is always located in the System (9x/Me) or System32 (NT/2K/XP) folder and should not normally figure in Msconfig/Startup! This file is located in a HelpHelp subfolder of the Windows or Winnt folder X WinCheck services.exe Added by the SOBER-S WORM! Note - this is not the legitimate services.exe process which is always located in the System (9x/Me) or System32 (NT/2K/XP) folder and should not normally figure in Msconfig/Startup! This file is located in a "ConnectionStatusMicrosoft" subfolder of the Windows or Winnt folder X Windows services.exe Added by the SOBER.X WORM! Note - this is not the legitimate services.exe process which is always located in the System (9x/Me) or System32 (NT/2K/XP) folder and should not normally figure in Msconfig/Startup! This file is located in a "WinSecurity" subfolder of the Windows or Winnt folder X WinStart services.exe Added by the SOBER.O WORM! Note - this is not the legitimate
    [Show full text]