My academic assignmentt
**
**Please help me in coding for this assignment

In Linux Ubuntu flavor, write a program in C language to do the following tasks.

1) Use fork ( ) system call to create a child process.
2) Child process should first take student name as input and then it should display student name that it takes
from user. At last, child process should display numbers from 0 to 5.
3) Parent process should first take Student ID as input and then it should display Student ID that it
takes from user. At last, parent process should display numbers from 6 to 10.
4) Output of the program should be like the one give below.

Enter Student Name: Mansoor Anwar
Student Name is: Mansoor Anwar
child: 0
child: 1
child: 2
child: 3
child: 4
child: 5
Enter Student ID: BC070651121
Student ID is: BC070651121
parent: 6
parent: 7
parent: 8
parent: 9
parent: 10

1) Do not write your program in other languages like Java, C++ etc. Write your program only in C language.
2) Do not execute your program in other operating systems like Windows, Mac etc. Execute your program only in Linux Ubuntu flavor.

from Wiki site I got this, u chnage it according to ur assignment,

thats all I can tell you

#include <stdio.h>   /* printf, stderr, fprintf */
#include <sys/types.h> /* pid_t */
#include <unistd.h>  /* _exit, fork */
#include <stdlib.h>  /* exit */
#include <errno.h>   /* errno */

int main(void)
{
   pid_t  pid;

   /* Output from both the child and the parent process
    * will be written to the standard output,
    * as they both run at the same time.
    */
   pid = fork();
   if (pid == -1)
   {   
      /* Error:
       * When fork() returns -1, an error happened
       * (for example, number of processes reached the limit).
       */
      fprintf(stderr, "can't fork, error %d\n", errno);
      exit(EXIT_FAILURE);
   }

   if (pid == 0)
   {
      /* Child process:
       * When fork() returns 0, we are in
       * the child process.
       */
      int j;
      for (j = 0; j < 10; j++)
      {
         printf("child: %d\n", j);
         sleep(1);
      }
      _exit(0);  /* Note that we do not use exit() */
   }
   else
   { 

      /* When fork() returns a positive number, we are in the parent process
       * (the fork return value is the PID of the newly created child process)
       * Again we count up to ten.
       */
      int i;
      for (i = 0; i < 10; i++)
      {
         printf("parent: %d\n", i);
         sleep(1);
      }
      exit(0);
   }
   return 0;
}

why parent is processing before child.

fork system call in Linux ubuntu

My academic assignmentt
**
**Please help me in coding for this assignment
Use C language to write a program. In that program main process creates a child process by using fork( ). Child
process should perform the following tasks.
1) Take VU student id from user and then display the VU student id
2) Child process should display its PID(process ID)
3) Child process should display its parent's PID
4) Child process should display value of its childpid variable (childpid is used to store the value returned by
fork( ))
5) Child process should take any value from 0 to 255 from user. After that child process exits and returns
that value to the parent process.
Parent process should perform the following tasks
1) Parent process should display its PID(process ID)
2) Parent process should display value of copy of its childpid variable (childpid is used to store the value
returned by fork( ))
3) When child process terminates then parent process receives a value from 0 to 255 from child process and
then parent process displays it.
Sample out put is given below.
SAMPLE OUTPUT
PARENT: I am the parent process!
PARENT: Here's my PID: 2861
PARENT: The value of my copy of childpid is 2862
PARENT: I will now wait for my child to exit.
CHILD: Enter your student id: bc12356487
CHILD: Student id is: bc12356487
CHILD: I am the child process!
CHILD: Here's my PID: 2862
CHILD: My parent's PID is: 2861
CHILD: The value of my copy of childpid is: 0
CHILD: Sleeping for 1 second...
CHILD: Enter any value from 0 to 255: 35
CHILD: Goodbye!
PARENT: Value returned by child code is: 35
PARENT: Goodbye!
Execute your program in Linux Ubuntu. Take screen shots of your program that you write in C, Commands that
you used to run your program in Linux Ubuntu and the out put displayed by your program. After taking screen
shots, send these screen shots to me properly in your assignment.
Note:
1) Do not write your program in other languages like Java, C++ etc. Write your program only in C language.
2) Do not execute your program in other operating systems like Windows, Mac etc. Execute your program only
in Linux Ubuntu flavor.
3) You should provide three screen shots. Required three screen shots that you should provide are given below.
i) Screen shots of your compete program that you write in C. Your screen shots should display your complete
program code that you write in C.
ii) Screen shot of Commands that you used to run your program in Linux Ubuntu.
iii) Screen shot of final output of your program shown.
4) If you will copy your assignment then you will get zero marks with no leniency.
5) Each student should display his own complete VU student ID and not the VU student ID of any other student.
6) In your program’s output, each student should indicate the execution of parent and child processes codes by
using the words PARENT: and CHILD: in the output display as shown in the sample output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.