Processes


– The child process is a duplicate of the parent process (it has the same program and data as the parent)


Download 0.8 Mb.
bet6/9
Sana16.06.2023
Hajmi0.8 Mb.
#1496696
1   2   3   4   5   6   7   8   9
Bog'liq
os eng

– The child process is a duplicate of the parent process (it has the same program and data as the parent)

– The child process has a new program loaded into it

Process Creation (Cont.)

• UNIX examples

– fork system call creates new process

– execve system call used after a fork to replace the process memory space with a new program.

Process Creation


int main()
{
pid_t pid; /* C Program Forking Separate Process
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
}

When does a process get terminated?

Process Termination

  • Process executes last statement and asks the operating system to delete it (exit)
    • Output data from child to parent (via wait)
    • Process’ resources are de-allocated by operating system
  • Parent may terminate execution of children processes (abort)

Threads

  • Process creation is heavy-weight while thread creation is light-weight
  • – Threads run within application

  • Multiple tasks with the application can be implemented by separate threads
    • Update display
    • Fetch data
    • Spell checking
    • Answer a network request
  • Can simplify code, increase efficiency
  • Kernels are generally multithreaded.

  • Download 0.8 Mb.

    Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling