Showing posts with label fork. Show all posts
Showing posts with label fork. Show all posts

How to Create process and display Process ID (pid) of Both Parent and Child

This program shows how to create process and display Process ID (pid) of Both Parent and Child processes. The process is created using the fork system call in UNIX (Linux) operating systems.

#include<stdio.h>
#include<dirent.h>
main(int argc,char **argv)
{

How to use fork and exec System Call

Using fork and exec System calls in Linux (UNIX) operating systems. Fork system call is used to create a child process from a parent process.
#include<stdio.h>
main()
{

How to make parent process wait till Completion of Child Process (Joining parent with child process)

How to make the parent process wait till the completion of execution of child process. The following C program makes the parent process to wait till the completion of its child process.

#include<stdio.h>
main()
{

How to make Child process an Orphan Process

C program in Linux or Unix to make a child process orphan:

Making child as orphan

#include<stdio.h>
main()
{

Creating A Process in Linux (UNIX) - fork() Example Program

The system call fork() is used to  create a new process in UNIX based operating systems and Linux systems. The fork() system call creates a child process when called from a parent process. Unix will make an exact copy of the parent's address space and give it to the child. Therefore, the parent and child processes have separate address spaces. Here is a C program which uses the fork() system call to create a process during execution. The program is commented well for better understanding.

Program

/*The program (parent process) reads an array from the user.
It sorts it in descending order.