Assignment 1
Assignment 1
Lab Assignment 1
Total Marks: 10
Task-1:
Write a c program that will open a file given from the command line argument and then it will
ask the user to input strings that will be written to that file. It will continue to ask the user to
enter a string as long as the user enters “-1”. If the given file does not exist in the directory, then
your program will automatically create the file.
Task-2:
Write a program that will create a child and another grandchild process. Every process will print
a line.
Now, write the program in such a way that the following output will be shown -
I am grandchild
I am child
I am parent
Task-3:
a = fork();
b = fork();
c = fork();
Now, write the full program, that will check the children’s PID and if it is odd then the process
will create another child process. Lastly, print how many processes have been created
considering the first parent process.
Task-4:
Write a program named “sort.c” where you will give some number from the command line
argument and the program will print the sorted array in descending order. Then, write another
program named “oddeven.c” which will take some numbers from the command line, then check
and print whether the numbers in the array are odd or even.
Now, you have to write a program that will create a child process and the child process will first
sort the array that you have declared in this program. And then, the parent process will print the
odd/even status for each number in the array.
oddeven
Task -5:
Write a program in c that the parent process will create one child process and 3 grandchild
processes and print their IDs