Linux Classroom Series – 15/Jul/2020

fork() and exec()

  • fork() creates a new process by duplicating the current process. The new process is referred as child and existing process from which duplicate is created is referred as parent Preview
    • Child will its own unique PID (Process ID),
    • The childs parent process ID will be same as parents process ID
    • Child doesn’t inherit parents memory locks and semaphore adjusments
    • Child doesn’t intherit outstanding I/O operations from parent.
    • On success, the PID of the child process is returned to parent and 0 is returned to child. On failure, -1 is returned to parent
  • exec() replaces the current process with new one. Preview Preview

Viewing Processes

  • The most commonly used command to view processes is ps
ps --help
man ps
  • Lets execute ps Preview
  • The result in this example lists two process process 1736 and 1809 which are bash and ps.
  • To get bigger picture lets try to execute ps x Preview
  • Adding the x opts tells ps to show all of the our processes regardless of what terminal they are controlled by. The presence of ? in the TTY column indicates no controlling terminal
  • State Meaning
    • R: Running
    • S: sleeping
    • D: Uninterruptible sleep
    • T: stopped
    • <: A high priority process
    • N: A low priority process
  • Lets get into more details of the process by executing ps aux Preview
  • Header Meaning
    • USER: USER ID. This is owner of process
    • %CPU: Cpu usage in percent
    • %MEM: Memory usage in percent
    • VSZ: Virtual Memory Size
    • RSS: Resident Set size. This is amount physical memory(RAM) the process is using in kilobytes
    • START: Time when the process started.
  • Ps command can tell you lot about what machine is doing at the moment when you typed the ps command
  • To get dynamic view of machines activity use top clear Preview
  • Also try htop Preview
  • PS command shows static info, whereas top and htop commands show us dynamic info

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin