Question: 2 . Short answer ( 3 sentences maximum ) : Explain why the following code fragment will not work as expected: pipe ( fd )

2. Short answer (3 sentences maximum):
Explain why the following code fragment will not work as expected:
pipe(fd);
switch(cpid = fork()){
case -1: perror("fork failed"); break;
case 0:
while(read(fd[0], buffer, sizeof(buffer))>0){
printf("recv msg: %s
", buffer);
}
break;
default:
for(i =0; i < num_msgs; i++){
write(fd[1], msg, sizeof(msg));
}
waitpid(cpid, NULL, 0);
break;
}
Bash
3. Write a bash function that will accept a two integer arguments, x and y, returning
0 if x is a factor of y or 1 if it is not. Invoke the function and print is a factor or
not a factor according to the result.
Sed
4. Write a sed script that will:
a. Remove the first number from a line, if it begins with a number
i. For these lines, surround the entire line in ... tags
b. Trim any repeat sequences of tabs and/or spaces down to a single space
c. Replace all sequences of digits that reside immediately prior to a
hyphen with a single x.
Example input:
25323xr output freq 150.32
8892vfr outbound N2137 cs 12-01-1990
ifr inbound N9983 heavy
end of data

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!