______ Selected Linux system calls (CS 273 (OS), Fall 2020)
Home
>>    




Selected Linux system calls

CS 273 (OS), Fall 2020

Basic file handling

  • open()
  • read()
  • write()
  • close()
  • creat()
    • Often, just use O_CREAT flag with open() instead
  • lseek()
  • mknod()


  • Example
    ~cs273/egs/mopen.c

File properties

  • fstat()
    • Writes values into struct stat variable allocated by caller
  • chmod()
  • chown()
  • umask()
    • arg: bitmask of bits to turn off when caller creates new file or dir

Directory operations

  • mkdir()
  • rmdir()
  • link()
  • symlink()
  • unlink()
  • chdir()

Other file-related calls

  • dup()
  • dup2()
  • pipe()
    • Provides two file descriptors for reading resp. writing


    Examples
    ls -s | sort -n
    ls -s | sort -n | grep -v '^total' > ls.out

  • utime()
    • set access and/or modification time for a file

File systems

  • mount()
  • umount()
  • chroot()

Input/output

  • ioctl()


  • Example
    ~cs273/egs/tryraw.sh

Memory management

  • brk()
  • sbrk()


  • Note
    These calls manage the total memory allocation for a process
    Use library routine malloc for dynamic memory allocation

Time

  • time()
    • seconds since the Epoch
  • times()
    • utime, stime for calling process
  • gettimeofday()
    • {sec, μsec} since the Epoch
  • settimeofday()
  • stime()
    • set number of seconds since the Epoch

Processes

  • fork()
  • execve()
  • exit()
  • wait()
  • waitpid()


  • Examples
    ~cs273/egs/forkeg.c

    ls
    emacs &
    ls > ls.out
    ls -s | sort -n

Process identification

  • getpid()
  • getgid()
    • Current gid for caller
  • getuid()
  • getppid()
    • Return pid of parent
  • getpgrp()
    • Return process group id of caller
  • setgid()
  • setuid()
  • getegid()
  • geteuid()
    • Effective uid, different when SETUID bit set or su invoked
  • setegid()
  • seteuid()
  • setpgrp()
    • Assign a process to another pgid in the same session

Signals

  • signal()
  • kill()
  • alarm()
  • pause()
  • setitimer()


  • Example
    ~cs273/egs/signal.sh

Miscellaneous process related calls

  • nice()
  • getrlimit()

BSD-style networking

More networking