My name is nyomangedar

OS202


Project maintained by nyomangedar Hosted on GitHub Pages — Theme by mattgraham

HOME


Top 10 List of Week 05

  1. week05.c explanation int (main) void { /** sizeof will return the size of “shared” that were defined in myweek05.h” */ int ssize = sizeof(shared);

/** open method will return the file descriptor of the directed file with parameter: SHAREMEM is the file path that will be opened, MYFLAGS = values that determine the method on how the files will be opened, CHMOD = values that determine the permission of the file. */ int fd = open(SHAREMEM, MYFLAGS, CHMOD);

/** fchmod method will change mode of a file, with parameter: fd = int variable consist of file description chmode = the mode that will change the previous mode */ fchmod(fd, CHMOD);

/** ftruncate method will causes the file from file description to have a size as the given length. fs = int variable consist of file description ssize = the given size of length bytes */ ftruncate(fs,ssize);

/** mmap will return address to the variable mymap with parameter: NULL = the starting address for the mapping, if the value is NULL then it is free to begin anywhere ssize = the number of bytes which to be mapped MYPROTECTION = permitted access to the file MYVISIBILITY = the nature of the map fd = file description of the file that will be mapped 0 = offset from where the file mapping started */ CHPTR mymap = mmap(NULL, ssize, MYPROTECTION, MYVISIBILITY, fd, 0);

/** strcpy will copy the string to the file destination mymap = the file destination SHARED = the source file taht will be copied */ strcpy(mymap, SHARED);

/** close the file */ close(fd); }

  1. week05.h explanation
    #include /** The header defines the following requests and arguments for use by the functions fcntl() and open(). */ #include /** The stdio.h header defines three variable types, several macros, and various functions for performing input and output. */ #include /** The string.h header defines one variable type, one macro, and various functions for manipulating arrays of characters. */ #include <sys/mman.h> /** sys/mman.h - memory management declarations */ #include <sys/stat.h> /** The <sys/stat.h> header shall define the structure of the data returned by the functions fstat(), lstat(), and stat().*/ #include <sys/types.h> /** The <sys/types.h> header shall include definitions for ssize_t. */ #include /** The header defines miscellaneous symbolic constants and types, and declares miscellaneous functions. */

  2. The Advantage of Virtual Memory
    Virtual memory involves the separation of logical memory as perceived by developers from physical memory.
    This separation allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available. Virtual memory makes the task of programming much easier, because the programmer no longer needs to worry about the amount of physical memory available.

  3. Virtual Address Space
    The virtual address space of a process refers to the logical (or virtual) view of how a process is stored in memory. Typically, this view is that a process begins at a certain logical address—say, address 0—and exists in contiguous memory.

  4. Demand Paging
    With demand paging, pages are loaded only when they are demanded during program execution. Pages that are never accessed are thus never loaded into physical memory. Therefore, we can avoid unnesecary memory usage by loading the entire program

  5. Copy-on-Write
    To avoid child process to copy the parent’s address we use a technique called copy-on-write, which works by allowing the parent and child processes initially to share the same pages. These shared pages are marked as copy-on-write pages, meaning that if either process writes to a shared page, a copy of the shared page is created.

  6. Page-Replacement
    When available memory runs low, a page-replacement algorithm selects an existing page in memory to replace with a new page. Page- replacement algorithms include FIFO, optimal, andLRU. PureLRU algorithms are impractical to implement, and most systems instead use LRU-approximation algorithms.

  7. Thrashing
    Consider what occurs if a process does not have “enough” frames—that is, it does not have the minimumnumber of frames it needs to support pages in the working set. The process will quickly page-fault. At this point, it must replace some page. However, since all its pages are in active use, it must replace a page that will be needed again right away. Consequently, it quickly faults again, and again, and again, replacing pages that it must bring back in immediately. This high paging activity is called thrashing.

  8. Memory Compression
    Memory compression is a memory-management technique that compresses a number of pages into a single page. Compressed memory is an alternative to paging and is used on mobile systems that do not support paging.

  9. Kernel Memory
    Kernel memory is allocated differently than user-mode processes; it is allocated in contiguous chunks of varying sizes. Two common techniques for allocating kernel memory are (1) the buddy system and (2) slab allocation.