Tuesday 3 November 2015

Child parent process for sorting using fork() call - Operating Systems

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
pid_t pid;
int i,j;
int a[5];
printf("\nEnter 5 numbers:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
pid=fork();
if(pid==0)
{
for(i=0;i<4;i++)
for(j=i+1;j<5;j++)
{
if (a[i]>a[j])
{
int temp;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}

for(i=0;i<5;i++)
printf("%d",a[i]);
}
}

No comments:

Post a Comment