Question

Write a program in C (called parallel) that creates children depending on how many lines you get from the first part of the c

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
void parallel(int n){
for(int i=0;i<n;i++){
if(fork()==0){
printf("I am a child with pid %d and my parent pid %d\n",getpid(),getppid());
exit(0);

}

}
for(int i=0;i<n;i++)
wait(NULL);

}

void main(){
int n;
printf(" ");
  
scanf("%d", &n);
parallel(n);

}

Add a comment
Know the answer?
Add Answer to:
Write a program in C (called parallel) that creates children depending on how many lines you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are required to write a C program on Unix/Linux in which the parent process creates...

    You are required to write a C program on Unix/Linux in which the parent process creates three child processes, lets them run concurrently, and waits for them to return and prints their exit status. The three child processes are assigned different tasks. Child one is to calculate and display the highest mark of a class of ten students for a unit. Child one is required to get the marks from the standard input (i.e. the keyboard). Child two is to...

  • Write a C program for Linux called pipes.c that does the following: In the main() function,...

    Write a C program for Linux called pipes.c that does the following: In the main() function, it creates a pipe using the pipe() function, then creates two child processes with fork(). Child 1 redirects stdout to the write end of the pipe and then executes with execlp() the "ps -aux" command. Child 2 redirects its input from stdin to the read end of the pipe, then it executes the "sort -r -n -k 5" command. After creating both children, the...

  • Please I need help with this problem Write a c++ program that will accept the names...

    Please I need help with this problem Write a c++ program that will accept the names of 3 processes as command-line arguments. Each of these processes will run for as many seconds as (PID%10)*3+5 and terminate. After those 3 children terminated, the parent process will reschedule each child. When all children have been rescheduled 3 times, the parent will terminate. Each child must print out its process id every time it runs.

  • Write a “C” program that creates a child process that prints out its pid and new...

    Write a “C” program that creates a child process that prints out its pid and new line and then calls pause() system call. Once it returns from the pause system call the child program must exit with code 5. The parent program must wait for the child process and print out the pid of the child process and the exit status with the following format: “childpid=%d,exitstatus=%d\n”.

  • C++ Write a program that asks for a number and then prints as many lines as...

    C++ Write a program that asks for a number and then prints as many lines as the user inputs. Each line contains as many pairs of characters ("*#") as the number of this line. It should look like the right half of a pyramid. Your version of the program must print the same result as the expected output. To to this lab, you must use two do-while loops. Two exceptions: When the user inputs a number less than 1, then...

  • Write a C++ program that creates a ragged table (i.e. a table with rows of different...

    Write a C++ program that creates a ragged table (i.e. a table with rows of different length) using a vector of vector of integers. Your program should prompt the user for a file name, open the file, read the content of the file and store it in a vector or vectors, and finally print the content of the vector of vectors. Sample Input: Enter the file name: data.dat A sample file might contain: 6 5 2 4 5 3 2...

  • In c programming, I need to write a program that reverses each of the lines in...

    In c programming, I need to write a program that reverses each of the lines in a file. The program accepts two command line arguments: The first one is the name of the input file The second is the name of the output file If the user didn't give two filenames, display an error message and exit. The program reads in each line of the input file and writes each line in reverse to the output file. Note, the lines...

  • a) Write a C-program that creates a chain of 10 processes and prints out their process...

    a) Write a C-program that creates a chain of 10 processes and prints out their process ids and relationships. For example, process 1 is the parent of process 2, process 2 is the parent of process 3, process 3 is the parent of 4 and so on. Each child has to print out all her ancestors identified by the process ids. b) Write a C-program that creates a fan of 10 processes. That is, process 1 is the parent of...

  • Write a C program called last10 that prints the last ten lines of a text file....

    Write a C program called last10 that prints the last ten lines of a text file. The program can be used from the command line with: last10 filename or last10 If there is no filename, last10 processes standard input.

  • [THIS SHOULD BE WRITTEN IN C++] The first argument, usually called argc, tells the program how...

    [THIS SHOULD BE WRITTEN IN C++] The first argument, usually called argc, tells the program how many command line arguments were passed to the program on its invocation. The second argument, argv, is an array of strings containing the arguments themselves. Write a main which prints out the arguments passed to the program. For example, when I run my program like this: ./prog apples bananas oranges it outputs: Argument #0 is ./prog Argument #1 is apple Argument #2 is bananas...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT