Systems Programming and Networking Concepts

Systems Programming

Definition of Systems Programming

  • Systems programming, or system programming, is the activity of programming computer system software.

  • Primary Distinction: Systems programming differs from application programming in that:
      - Application Programming:
        - Aims to produce software that provides direct services to users (e.g. word processors).
      - Systems Programming:
        - Aims to produce software and software platforms that provide services to other software, are performance constrained, or both (e.g. operating systems, computational science applications, game engines, industrial automation, and software as a service applications).

  • Hardware Awareness: Systems programming requires a high degree of hardware awareness.
      - Goals:
        - Achieve efficient use of available resources.
        - Important for software that is performance-critical.
        - Small efficiency improvements can lead to significant savings in time or money.

Examples of Systems Programming Tasks

  • Developing Operating Systems:
      - Core software that manages computer hardware and software resources.

  • Creating Device Drivers:
      - Enable communication between hardware and the operating system.

  • Writing Compilers and Interpreters:
      - Translate high-level programming languages into machine code.

  • Building Network Protocols:
      - Software for inter-computer communication.

  • Developing Firmware:
      - Software that controls hardware devices.

Contrast with Application Programming

  • While systems programming focuses on:
      - Underlying platform and hardware management,

  • Application programming concerns itself with:
      - Software that directly provides services to end-users, such as:
        - Word processors
        - Web browsers
        - Games

Rationale for Systems and Network Programming Class

  • The course is titled “Systems and Network Programming” because:
      - The learning environment is much closer to the Operating System (Linux) than most application programmers typically encounter.
      - We are learning/using a low-level programming language that brings us closer to hardware and memory management.
      - We will utilize library functions in C that most application programmers would never use, such as:
        - fork
        - exec
        - signals
        - pipes
        - Raw socket calls.

  • Final Project: Building a process management system.
      - Note: We will not be building the processes that are managed; this task is assigned to application programmers.

System Command

  • Functionality: The system() function creates a new process that runs a specified command.

  • Prototype: int system(const char *command).

  • Return Value:
      - Returns after the command has completed.
      - Returns -1 on error; otherwise, it returns the exit status of the command executed.

  • Output Handling:
      - Outputs of the command go directly to stdout (e.g., bash shell).
      - If the output is important for further processing:
        - Redirect the output to a file as part of the system call.
        - Use pipes to process information in the same program.
      - Use Case: Most useful for scenarios where only the return value of the system call is of interest, not the command output.
      - Example: Refer to ../CProgs/system/systest.c for a practical example.

popen Command

  • Functionality: The popen() function opens a process to execute a given command by creating a pipe, forking, and invoking the shell.

  • Prototype: FILE *popen(const char *command, const char *type).

  • Return Value:
      - Returns after the command has completed.
      - Returns handle to a file containing the pipe to the process, or NULL on failure.

  • Type Argument:
      - Since a pipe is unidirectional, the type argument specifies either reading or writing, but not both.
      - The resulting stream is read-only or write-only corresponding to the type.

  • Examples:
      - Refer to ../CProgs/system/ptest.c for an example of reading from a pipe.
      - Refer to ../CProgs/system/pcalc.c for an example of writing to a pipe.