Technische Universität Braunschweig
  • Studium & Lehre
    • Vor dem Studium
      • Informationen für Studieninteressierte
      • Studiengänge von A-Z
      • Bewerbung
      • Warum die TU?
    • Im Studium
      • Erstsemester-Hub
      • Semestertermine
      • Lehrveranstaltungen und Qualifikationen
      • Studienorganisation
      • Beratungsnavi
      • Finanzierung und Kosten
      • Besondere Studienbedingungen
      • Gesundheit & Wohlbefinden
      • Studentisches Engagement
    • Nach dem Studium
      • Career Service
      • Alumni*ae
      • Exmatrikulation und Vorbeglaubigung
      • Nach dem Abschluss
    • Strategien und Qualitätsmanagement
      • Qualitätsmanagement
      • Studienqualitätsmittel
      • TU Lehrpreis
    • Für Lehrende
      • Informationen für Lehrende
      • Konzepte
      • Lernmanagementsystem Stud.IP
      • Impact Learning
    • Kontakt
      • Studienservice-Center
      • Sag's uns: Ideen‑ & Beschwerdestelle Studium & Lehre
      • Zentrale Studienberatung
      • Immatrikulationsamt
      • Abteilung 16 - Studium und Lehre
      • Career Service
      • Projekthaus
  • Forschung
    • Forschungsprofil
      • Forschungsschwerpunkte
      • Exzellenzcluster der TU Braunschweig
      • Forschungsprojekte
      • Forschungszentren
      • Forschungsprofile der Professuren
    • Frühe Karrierephase
      • Förderung in den frühen Phasen der wissenschaftlichen Karriere
      • Promotion
      • Postdocs
      • Nachwuchsgruppenleitung
      • Junior Professur und Tenure-Track
      • Habilitation
      • Service-Angebote für Wissenschaftler*innen
    • Forschungsdaten & Transparenz
      • Transparenz in der Forschung
      • Forschungsdaten
      • Open Access Strategie
    • Forschungsförderung
      • Netzwerk Forschungsförderung
      • Datenbanken und Stiftungen
    • Kontakt
      • Forschungsservice
      • Graduiertenakademie
      • Organisation wissenschaftlicher Veranstaltungen
  • Transfer
    • Transferprofil
      • Transferstrategie "TIES® with Impact"
      • Technologietransfer
      • Wissenstransfer
      • Relationship Management
      • Transferprojekte
    • Innovation
      • Startups
      • Patente
      • Impact Map
    • Schule-Uni-Angebote
      • Webportal für Schule-Uni-Aktivitäten
      • Kinder-Uni Vorlesungen
      • Kinder-Uni Podcast
      • LeoLabs – Campuslabore für Schüler*innen
      • LeoVan – Mobile Experimente für Schulen
      • School Outreach Fonds
      • Hochschulinformationstag
    • Für Unternehmen
      • Deutschlandstipendium
      • Freunde & Förderer
    • Für Alumni*ae
      • Dem Netzwerk beitreten
      • Alumni*ae kennen lernen
      • Alumni*ae Talks
      • Campustouren
    • Für alle
      • Community Café
      • Community Podcast
      • Uni-Shop
  • International
    • Internationale Studierende
      • Warum Braunschweig?
      • Studium mit Abschluss
      • Austauschstudium
      • TU Braunschweig Summer School
      • Schüler*innen von deutschen Auslandsschulen
      • Geflüchtete
      • International Student Support
      • International Career Service
    • Wege ins Ausland
      • Studium im Ausland
      • Praktikum im Ausland
      • Lehren und Forschen im Ausland
      • Arbeiten im Ausland
    • Internationale Forschende
      • Welcome Support for International Researchers
      • Service für gastgebende Einrichtungen
    • Sprachen und interkulturelle Kompetenzvermittlung
      • Deutsch lernen
      • Fremdsprachen lernen
      • Interkulturelle Kompetenzvermittlung
    • Internationales Profil
      • Internationalisierung
      • Internationale Kooperationen
      • Strategische Partnerschaften
      • Internationale Netzwerke
    • International House
      • Wir über uns
      • Kontakt & Sprechstunden
      • Aktuelles und Termine
      • Newsletter, Social Media, Podcast & Videos
      • Stellenausschreibungen
  • Die TU Braunschweig
    • Unser Profil
      • Ziele & Werte
      • Ordnungen und Leitlinien
      • Hochschulentwicklung 2030
      • Ecoversity – die TU Braunschweig als Ökosystem Universität
      • Chancengleichheit
      • Diversity
      • Nachhaltigkeit
      • Fakten & Zahlen
      • Unsere Geschichte
    • Leitung & Organisation
      • Das Präsidium
      • Stabsstellen
      • Verwaltung
      • Einrichtungen
      • Organe, Statusgruppen und Kommissionen
      • Studierendenschaft
    • Karriere
      • Arbeiten an der TU
      • Stellenmarkt
      • Berufsausbildung an der TU
      • Informationen und Angebote für neue Mitarbeitende
    • Fakultäten
      • Carl-Friedrich-Gauß-Fakultät
      • Fakultät für Lebenswissenschaften
      • Fakultät Architektur, Bauingenieurwesen und Umweltwissenschaften
      • Fakultät für Maschinenbau
      • Fakultät für Elektrotechnik, Informationstechnik, Physik
      • Fakultät für Geistes- und Erziehungswissenschaften
      • Institute von A-Z
    • Die TU für alle
      • Gasthörer*innen & Senior*innenstudium
      • Universitätsbibliothek nutzen
      • Das Studierendenhaus
      • Podcasts
    • Veranstaltungen
      • Veranstaltungskalender
      • Angebote für Schüler*innen
      • Hochschulinformationstag (HIT)
  • Suche
  • Schnellzugriff
    IBR Login
    • Bibliothek
    • Mailinglisten
    • Webmail
    • Knowledgebase
    • Wiki
    • Account Management
    • Service-Status
    • Personensuche
    • Webmail
    • cloud.TU Braunschweig
    • Messenger
    • Mensa
    • TUconnect (Studierendenportal)
    • Im Notfall
    • Stud.IP
    • UB Katalog
    • Forschungsinformations-System (FIS)
    • Status GITZ-Dienste
    • Störungsmeldung GB3
    • Informationsportal (Beschäftigte)
    • Linksammlung
    • DE
    • EN
    • Instagram
    • YouTube
    • LinkedIn
    • Mastodon
    • Bluesky

    Menü
    Technische Universität BraunschweigIBR
    • Struktur
    • Fakultäten
    • Carl-Friedrich-Gauß-Fakultät
    • Institute
    • Institut für Betriebssysteme und Rechnerverbund
    • Prof. Dr.-Ing. Christian Mengert-Dietrich
    • Advent(2)
    • The cat on the tip of the iceberg
    Logo IBR
    • Institut für Betriebssysteme und Rechnerverbund
      • News
      • Wir über uns
        • Gesamtes Team
        • Anreise
        • Raumplan
        • Projekte
        • Veröffentlichungen
        • Software
        • News Archiv
      • Connected and Mobile Systems
        • Team
        • Lehrveranstaltungen
        • Abschlussarbeiten
        • Projekte
        • Veröffentlichungen
        • Software
        • Datensätze
      • Verlässliche Systemsoftware
        • Übersicht
        • Team
        • Lehre
        • Arbeiten & Jobs
        • Forschung
        • Publikationen
      • Algorithmik
        • Team
        • Lehrveranstaltungen
        • Abschlussarbeiten
        • Projekte
        • Veröffentlichungen
      • Mikroprozessorlabor
      • Studium
        • Wintersemester 2026/2027
        • Sommersemester 2026
        • Abschlussarbeiten
      • Spin-Offs
        • Docoloc
        • bliq (formerly AIPARK)
        • Confidential Technologies
      • Forschungsverbünde
        • IST.hub
    • Task Overview
    • Git repository
    • Mailing list
    • Matrix-Channel

    The cat on the tip of the iceberg

    ☃️
    Git-Repository: Template Solution Solution-Diff (Solution is posted at 18:00 CET)
    Workload: 46 lines of code
    Important System-Calls: open(2), pread(2), close(2)
    Illustration for this exercsie

    Welcome to the Christmas village, where the ELFs (see elf(5)) live and work together to prepare everything for Christmas. While they are Santa's little helpers, they have a rich culture on their own. They are open to new technologies, but also have a rather strong technocratic culture that might sometimes irritate you. Their favorite operating system is of course Linux and they are also into low-level systems hacking to squeeze out the last bit of performance from their machines. While cooling is no problem at the north pole, getting enough energy from renewables is hard up there. Also, they often find themselves in a NIH (Not Invented Here) situation, where they solve problems that others have already solved. We are guests in the village for the next 24 days, so this is a good opportunity to get some in depth knowledge about Linux and its specifics. Come and join me in our stay at the Christmas village where the ELFs like invoking system calls as much as glueing together gifts for the children of the world.

    Introduction

    System calls are commands, like read! or write! for our operating system. They are verbs and they are an imperative. But it is not enough to order an action, we also have to specify on what object the action should be performed. And while integers or strings make good arguments, we often have to address some stateful object within the operating system. I am talking of file descriptors (FDs).

    First of all, I have to tell you something. But it has to be in secret... so come closer... closer. OK! Now it's good. File descriptors are not (only) about files anymore. They are a much more general concept that we use to address kernel objects from user space. On the surface, for our program, they are just integers. For example, have you already heard that 1 is usually the standard output of a program? But what happens, if we use 1 with, for example, write(2)?

    write(1, "foo", 3)
    

    When the OS receives those three arguments, it will consult the file-descriptor table (struct fdtable) of the current process and use the given integer as an index to retrieve a struct file. However, you might already have guessed it, these objects are not necessarily only open files, but they can represent all sorts of in-kernel objects that come with a struct file interface. For example, like our standard output, they can be a terminal or, as we will see later, point to another process.

    You have to imagine file descriptors as a handle in user space that we can grab, store and pass around in our program, while there is an in-kernel object connected to it. Or, to say it differently, the file descriptor is just the tip of the iceberg.

    Task

    We take a soft start in our Advent(2), and today's task is to write a simple version of the program cat(1). cat takes N file names as command-line arguments, concatenates their contents, and writes the result to its standard output.

    For this task, it is not necessary to use malloc(3), but you can get away with a globally allocated char buffer[4096] array.

    System Calls

    • open(2): The open system call takes a filename and some flags and opens the file. Thereby, it creates a new struct file in the kernel, finds a free slot in the struct fdtable and gives you the positive index. If the operation fails, you will get a negative integer.
    • read(2): Reads data, up to count bytes, from the file into the given buffer. Thereby, the kernel remembers the "current position" of the open file in the struct file (f_pos). If you want to read at an arbitrary position, you should use pread(2) or reposition the file pointer with lseek(2).

    • close(2): Removes the fdtable entry and deallocates the struct file if we were the last owner. Quiz: Can multiple entries of fdtable point to the same struct file? (hint: yes).

    Last modified: 2023-12-01 15:52:27.750730, Last author: , Permalink: /p/advent-01-open


    aktualisiert am 01.12.2023, 15:52 von Prof. Dr.-Ing. Christian Mengert-Dietrich
    http://www.ibr.cs.tu-bs.de/users/dietrich/advent/01-open/index.xml · abgerufen am 23.11.2026

    Für alle

    Stellenmarkt der TU Braunschweig
    Jobbörse des Career Service
    Merchandising
    Sponsoring- & Spendenleistungen
    Vertrauenspersonen für Hinweisgeber

    Für Studierende

    Semestertermine
    Lehrveranstaltungen
    Studiengänge von A-Z
    Informationen für Erstsemester
    TUCard

    Interne Tools

    Status GITZ-Dienste
    Handbuch für TYPO3 (Intern)
    Corporate Design-Toolbox (Intern)
    Glossar (DE-EN)
    Meine Daten ändern
    Hochschulöffentliche Bekanntmachungen

    Kontakt

    Technische Universität Braunschweig
    Universitätsplatz 2
    38106 Braunschweig
    Postfach: 38092 Braunschweig
    Telefon: +49 (0) 531 391-0

    Anreise

    © Technische Universität Braunschweig
    Impressum Datenschutz Barrierefreiheit

    Zur anonymisierten Reichweitenmessung nutzt die TU Braunschweig die Software Matomo. Die Daten dienen dazu, das Webangebot zu optimieren.
    Weitere Informationen finden Sie in unserer Datenschutzerklärung.