Computers and Technology, 22.09.2020 16:01 janayshas84
The following program is designed to echo a message from one child process to another, with upper and lowercase letter reversed. The program reliably outputs just the message "h" and then quits. Explain in a very clearly why this is the output. Suggest how the program could be corrected to produce the expected output.
#include
#include
#include
#include
#include
#include
int main()
{
int fd1[2];
int fd2[2];
char message[] = "Hello, world!\n";
char buffer[100];
pid_t pid1;
pid_t pid2;
if (pipe(fd1) == -1)
{ return 1;
}
if (pipe(fd2) == -1)
{ return 1;
}
pid1 = fork();
pid2 = fork();
if (pid1 < 0)
{ return 1;
}
if (pid2 < 0)
{ return 1;
}
if (pid1 > 0)
{
close(fd2[0]);
write(fd2[1], message, strlen(message)+1);
close(fd2[1]);
close(fd1[1]);
read(fd1[0], buffer, 100);
close(fd1[0]);
printf("%s", buffer);
}
else if (pid2 > 0) {
close(fd2[1]);
read(fd2[0], buffer, 100);
close(fd2[0]);
close(fd1[0]);
for (int i=0; i
if(islower(buffer[i])) {
buffer[i] = toupper(buffer[i]);
}
else {
buffer[i] = tolower(buffer[i]);
}
sleep(1);
write(fd1[1], &buffer[i], 1);
}
close(fd1[1]);
}
return 0;
}
Answers: 3
Computers and Technology, 22.06.2019 06:00
The width of a piece of rectangular land is 5m shorter rhan 1/3 of its length .find the width of the land if the length is 60m,150m.
Answers: 1
Computers and Technology, 22.06.2019 11:30
Write a function so that the main program below can be replaced by the simpler code that calls function original main program: miles_per_hour = float( minutes_traveled = float( hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('miles: %f' % miles_traveled) sample output with inputs: 70.0 100.0 miles: 116.666667
Answers: 3
Computers and Technology, 22.06.2019 20:10
Assume that minutes is an int variable whose value is 0 or positive. write an expression whose value is "undercooked" or "soft-boiled" or "medium-boiled" or "hard-boiled" or "overcooked" based on the value of minutes. in particular: if the value of minutes is less than 2 the expression's value is "undercooked"; 2-4 would be a "soft-boiled", 5-7 would be "medium-boiled", 8-11 would be "hard-boiled" and 12 or more would be a "overcooked".
Answers: 1
Computers and Technology, 23.06.2019 07:00
Why were most movies from the late 1890s until the early 1930s only filmed in black and white? there were only a few people who could afford the technology to produce color motion pictures back then. audiences did not want color motion pictures until later. the film used to make color motion pictures often overheated, which was a safety hazard, so it was generally not allowed. color films had to be hand-colored, frame by frame.
Answers: 3
The following program is designed to echo a message from one child process to another, with upper an...
Mathematics, 19.06.2021 02:40
Mathematics, 19.06.2021 02:40
Mathematics, 19.06.2021 02:40
Mathematics, 19.06.2021 02:40
Mathematics, 19.06.2021 02:40
Biology, 19.06.2021 02:40
Mathematics, 19.06.2021 02:40
Mathematics, 19.06.2021 02:40
Mathematics, 19.06.2021 02:40