1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sidana [21]
4 years ago
7

Write a C program using the fork() system call that generates this sequence in the child process. The starting number will be pr

ovided from the command line. For example, if 8 is passed as a parameter on the command line, the child process will output 8, 4, 2, 1. Have the parent invoke the wait() call to wait for the child process to complete before exiting the program. Perform necessary error checking to ensure that a positive integer is passed on the command line. Following are some running examples, assuming the compiled program named b.out:
Engineering
1 answer:
Digiron [165]4 years ago
7 0

Answer:

Program using the fork()

Explanation:

// code to create three child  

// process of a parent  

#include <stdio.h>  

#include <stdlib.h>  

#include <unistd.h>  

// Driver code  

int main()  

{  

int pid, pid1, pid2;  

// variable pid will store the  

// value returned from fork() system call  

pid = fork();  

// If fork() returns zero then it  

// means it is child process.  

if (pid == 0) {  

 // First child needs to be printed  

 // later hence this process is made  

 // to sleep for 3 seconds.  

 sleep(3);  

 // This is first child process  

 // getpid() gives the process  

 // id and getppid() gives the  

 // parent id of that process.  

 printf("child[1] --> pid = %d and ppid = %d\n",  

  getpid(), getppid());  

}  

else {  

 pid1 = fork();  

 if (pid1 == 0) {  

  sleep(2);  

  printf("child[2] --> pid = %d and ppid = %d\n",  

   getpid(), getppid());  

 }  

 else {  

  pid2 = fork();  

  if (pid2 == 0) {  

   // This is third child which is  

   // needed to be printed first.  

   printf("child[3] --> pid = %d and ppid = %d\n",  

    getpid(), getppid());  

  }  

  // If value returned from fork()  

  // in not zero and >0 that means  

  // this is parent process.  

  else {  

   // This is asked to be printed at last  

   // hence made to sleep for 3 seconds.  

   sleep(3);  

   printf("parent --> pid = %d\n", getpid());  

  }  

 }  

}  

return 0;  

}  

You might be interested in
A storm sewer is carrying snow melt containing 1.2 g/L of sodium chloride into a small stream. The stream has a naturally occurr
galina1969 [7]

Answer:

Given Data:

concentration of sewer Csewer = 1.2 g/L

converting into mg/L = Csewer = 1.2 g/L x 1000 mg/g = 1200 mg/L

flow rate of sewer Qsewer = 2000 L/min

concentration of sewer Cstream = 20 mg/L

flow rate of sewer Qstream = 2m3/s

converting Q into L/min = 2m3/s x 1000 x 60 = 120000 L/min

mass diagram is

6 0
3 years ago
It was determined by the forensic engineers that the historic collapse of the Minneapolis Interstate Bridge was due to
Alexandra [31]

It was determined by the forensic engineers that the historic collapse of the Minneapolis Interstate Bridge was due to design and construction flaws. It led to the collapse of the structure.

<h3>What is the Minneapolis Interstate Bridge?</h3>

The Minneapolis Interstate Bridge is a well-known bridge that was constructed in Minneapolis city in 1967.

It has been demonstrated that the collapse of this bridge constructed in Minneapolis was due to its inadequate load capacity.

In architecture, it is fundamental to measure the amount of weight that a structure (in this case, a bridge) can sustain in a given period of time.

Learn more about the bridge construction here:

brainly.com/question/24686952

4 0
2 years ago
Explain why the following scenario fails to meet the definition of a project description.
s344n2d4d5 [400]

Answer:

The youth hockey training facility

Explanation:

7 0
3 years ago
Reference sources reveal that a workpiece material has a unit horsepower of 1.6 hp/in3/min. For a turning operation, the cutting
Troyanec [42]

The question is incomplete. We have to calculate :

a). the cutting force

b). volumetric metal removal rate, MRR

c). the horsepower required at the cut

d). if the power efficiency of the machine tool is 90%, determine the motor horsepower

Solution :

Given :

Cutting velocity (v) = 500 ft/min

                               = 500 x 12 in/min

                               = 6000 in/min

Feed , f = 0.025 in/rev

Depth of cut, d = 0.2 in

b). Volumetric material removal rate, MRR = v.f.d

                                                                      = 6000 x 0.025 x 0.2

                                                                      = 30 $in^3 / min$

c). Horsepower required = MRR x unit horsepower

                                         = 30 x 1.6

                                         = 48 hp

a). Cutting force,

$F=\frac{power}{cuting \ velocity}$

    $=\frac{48 \times 550}{500 /60}$                (1 hp = 550 ft lbf /sec)

   = 3168 lbf

d). Machine HP required

  $=\frac{HP}{\eta}$

 $=\frac{48}{0.9}$

= 53.33 HP

6 0
3 years ago
A landowner and a contractor entered into a written contract under which the contractor agreed to build a building and pave an a
Leya [2.2K]
The contractor definitely breached the contract
4 0
3 years ago
Other questions:
  • The difference between absolute viscosity and kinematic viscosity is a. the absolute viscosity is the mass density divided by th
    10·1 answer
  • Definition of permanent, semi permanent and temporary heat setting
    5·1 answer
  • Name two parts that are sometimes made of hard metal and pressed into the head​
    6·1 answer
  • What are the 5 basic types of propulsion systems​
    6·1 answer
  • A robot with artificial intelligence would best be suited for
    11·1 answer
  • Select the correct answer.
    12·1 answer
  • Which geometric curved solids are most commonly used by engineers?
    8·2 answers
  • Type the correct answer in the box. Spell all words correctly. Type the exact term Mike should use for the given scenario. Mike
    8·2 answers
  • Select the correct answer.
    8·1 answer
  • Please Help It's a lot I'm sorry. =(
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!