Systems Programming 1 2015F t1

download Systems Programming 1 2015F t1

of 15

description

System Programming Notes. Unix and C#

Transcript of Systems Programming 1 2015F t1

  • 11

    Operating Systems

    The operating system (OS) is the most important program that runs on a computer.The OS manages and controls a computers activities.

    11

    Operating Systems

    The operating system (OS) is the most important program that runs on a computer.The OS manages and controls a computers activities.

    The popular operating systems:1. Microsoft Windows2. Mac OS X3. Linux4. UNIX

  • 22

    Operating Systems

    Users and applications access the computers hardware via the operating system.

  • Programs and Processes

    Unix:a multitasking, multiuser computer operating system that exists in many variants. The original Unix was developed at AT&T's Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

    The C programming language was designed by Dennis Ritchie as a systems programming language for Unix.

    Both Unix and the C programming language were developed by AT&T and distributed to government and academic institutions, which led to both being ported to a wider variety of machine families than any other operating system.

    3

  • Process

    In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity.

    Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.

    A process is a dynamic entity.

    PuTTY: (UNIX connection)click putty; use following information to set up and connecthost name: alpha.fdu.educonnection type: SSHchange keyboard under Terminal at left panelThe backspace key: control-HThe function key and keypad: VT100+

    4

  • 5Process

    http://www.putty.org

  • 66

    Process

  • 7ProcessFundamental to all operating systems is the concept of a process.

    A process consists of1. Executing program2. Its current values3. State information4. The resources used by the O.S. to manage

    the execution of the process

  • 8UNIX Operating System

    In UNIX-based operating system, at any point in time, multiple processes appear to be executing concurrently.

    The UNIX operating system run on platform that has a single processing unit capable of supporting many active processes.Meaning, at any point in time only one process is actually being worked upon.

    By rapidly changing the process it is currently executing, the UNIX operating system gives the appearance of concurrent process execution.

  • 9Multiprogramming or Multitaskingallows multiple programs to run simultaneously by sharing

    the same CPU. Allowing you to use a word processor to edit a file at the same time as your Web browser is downloading a file.

    Multithreading allows a single program to execute multiple tasks at the same

    time. At the word processing editing and saving are two tasks within the same application, run concurrently.

    Multiprocessing or parallel processinguses two or more processors together to perform subtasks

    concurrently and then combine solutions of the subtasks to obtain a solution for the entire task.

  • 10

    ProgramA program is an inactive, static entity consisting of a set of instructions and associated data.

    We can consider a program to be in one of two basic formats:1. Source program non-executable

    A source program is a series of valid statements for a specific programming language (such as C, C++, Java, ).The source program is stored in a plain ASCII text file.

    2. Executable program not displayable on the terminal of printed by the userAn executable program is a source program that, by way of a translating program such as a compiler, assembler, ..etc, has been put into a special format that the O.S. can execute (run).

  • 1111

    ASCII The American Standard Code for Information Interchange(ASCII ) is a character-encoding scheme originally based on the English alphabet that encodes 128 specified characters.

  • 12

    /* Display Hello World 3 times */

    #include #include #include #include #include

    char *cptr="Hello World\n"; // static by placementchar buffer1[25];

    void main(void){void showit(char *); // function prototypeint i = 0; // automatic variablestrcpy(buffer1, "A demonstration\n"); // library functionwrite(1, buffer1, strlen(buffer1)+1); // system callfor(; i

  • 13

    Basic printf conversions

    malloc: Allocates main memory.#include void *malloc(size_t size); where size_t is unsigned int or long

  • 14

    Library Functions

    Function:A function is a collection of declarations and statements that carries out a specific action and/or returns a value.

    1. Defined by the user2. Previously defined: stored in object code format in

    library files

    Object code format is a special file format that is generated as an intermediate step when an executable program is produced.Like executable files, object code files are also not displayed to the screen or printed.

    Library functions: functions stored in library files

  • 1515

    Library Functions/usr/lib: The standard location for library files in most UNIX systems.

    /usr/local/lib: Ancillary library files

    By convention the three-letter prefix for library file is lib and the file extension is .a. The UNIX archive utility ar, which maintains library files, can be used to examine their contents.

    Ex:> ar -t /usr/lib/libc.a | pr -4 t

    ar: create, modify and extract from archivest: display a table listing the contentspr: convert text files for printing-4: output to screen in a four-column format-t: omit page headers and trailers