Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Parallel Processing ProgramsRSS Feeds

Program to simulate process synchronization, call wait function so that the executing process gets blocked and then print their process ids

Posted By: Leona Schmidt     Category: C Programming     Views: 4341

Write a C Program to simulate process synchronization, call wait function so that the executing process gets blocked and then print their process ids before and after calling wait

Code for Program to simulate process synchronization, call wait function so that the executing process gets blocked and then print their process ids in C Programming

int main()
{
        int i,pid;

        printf("pid : %d \n",pid);

        pid=fork();

        printf("pid : %d \n",pid);

        printf("\n");

        if(pid==0)
        {
                printf("Child starts\n");

                for(i=0;i<5;i++)
                {
                        printf("i : %d\n",i);
                        printf("\n");
                }
                printf("Child ends\n");
        }
        else
        {
                printf("\nBefore wait\n");
                printf("getpid : %d\n",getpid());
                pid=wait(0);
                printf("\npid : %d\n",pid);
                printf("After wait\n");
                printf("Parent\n");
                printf("getpid : %d\n",getpid());
        }
}



















Output:

[04mca8@LINTEL pp]$ ./a.out
pid : 8884256
pid : 0

Child starts
i : 0

i : 1

i : 2

i : 3

i : 4

Child ends
pid : 23325


Before wait
getpid : 23324

pid : 23325
After wait
Parent
getpid : 23324
  
Share: 



Leona Schmidt
Leona Schmidt author of Program to simulate process synchronization, call wait function so that the executing process gets blocked and then print their process ids is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!