User Tools

Site Tools


cso:lab_c

C language lab

Description

  • To get to know the lab environment.
  • Basic process creation and shared memory handling in C language.

Lab Contents

  1. Introduction to the 116 Lab
    1. GNU Linux environment
      1. login/logout
    2. Graphical User Interface - GUI:
      1. localization
      2. window handling
      3. file management, editing
    3. Command Line Interface - CLI:
      1. shell: bash
      2. localization: locale
      3. your friend: man [section] topic
        (note: man displays the manual through a pager which allows to scroll (up/down arrows) and search (/keyword), to exit just press q as quit)
      4. file management: ls, cd, cp, mv, mkdir
      5. process management: ps, ^z, jobs, fg, bg, &, echo $?
      6. command history (up/down arrows), history search: ^r
    4. Editors: gedit
  2. C compiler
    1. gcc -Wall source_file.c -o executable_file
    2. to run an executable issue: ./executable_file
    3. Download and save the following example example: hello_world.c
    4. Read the above program, is everything clear to you?
    5. What does the following variables do: argc, argv, status?
    6. Compile the program with gcc.
    7. Run the program with different number of arguments.
      Do you see what happens?
      Do you know why?
    8. Upon finishing check process exit (completion) status: echo $?
  3. Shared memory
    1. Currrent Shared Memory allocation can be investigated using the following tools: ipcs, ipcrm, ipcmk
    2. Download and save the following program: shm.c
    3. Take a look at it. What does it do?
    4. Read the manual (using 'man' command) regarding the following function calls used in the program. What do they do?
      1. sleep(): man 3 sleep
      2. time(): man 2 time
      3. srand(): man 3 srand
      4. rand(): man 3 rand
    5. What does stop message represent?
    6. Compile the program and run it several times.
    7. Why does it give different values each time it is run?
    8. Make sure, that your processes clean up Shared Memory (use ipcs, ipcrm commands).
cso/lab_c.txt · Last modified: 2021/01/08 14:10 (external edit)