Problem 7 (System Calls) Bookmark this page Where and what? Consider the following program. It opens filel and file2 which have already been created with: rm filel; rm file2; touch filel; touch file2; echo "ghi" > filel echo "gst"> file2 Therefore, each file contains 4 bytes. Here is the program (it will not compile as is because it contains a question mark): /* problem7.c */ #include int main(void) { } gxi char buffer= 'W'; open ("file1", 2); open("file2", 2); lseek (3, ?,1); write(3, &buffer, 1); Ilseek (4, -2, 2); write(4, &buffer, 1); read (0, &buffer, 1); write(4, &buffer, 1); lseek (3,-3,2); write(3, &buffer, 1); write(4,"\n",1); lseek (4,1, 0); write(4, &buffer, 1); Without a further header file compilation will produce a warning, but this will not affect this problem. When you enter a certain character and the single question mark is replaced with an appropriate number cat file1 produces: gxWx close (3); close (4); and cat file2 produces: What is that number and what is that character? The single question mark (?) should be replaced with: After the program starts you should enter the character:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

These operations are using C syntax and System Calls



Problem 7 (System Calls)
Bookmark this page
Where and what?
Consider the following program. It opens filel and file2 which have already been created with:
rm filel; rm file2; touch filel; touch file2;
echo "ghi" > filel
echo "gst"> file2
Therefore, each file contains 4 bytes.
Here is the program (it will not compile as is because it contains a question mark):
/* problem7.c */
#include <unistd.h>
int main(void)
{
}
char buffer = 'W';
open("file1", 2);
open ("file2", 2);
lseek (3, ?,1);
write(3, &buffer, 1);
lseek (4, -2, 2);
write(4, &buffer, 1);
read (0, &buffer, 1);
write(4, &buffer, 1);
lseek (3,-3, 2);
write(3, &buffer, 1);
gxWx
write(4,"\n",1);
lseek (4,1, 0);
write(4, &buffer, 1);
close (3);
close (4);
Without a further header file compilation will produce a warning, but this will not affect this problem.
When you enter a certain character and the single question mark is replaced with an appropriate number cat file1 produces:
gxi
and cat file2 produces:
What is that number and what is that character?
The single question mark (?) should be replaced with:
After the program starts you should enter the character:
Save
Transcribed Image Text:Problem 7 (System Calls) Bookmark this page Where and what? Consider the following program. It opens filel and file2 which have already been created with: rm filel; rm file2; touch filel; touch file2; echo "ghi" > filel echo "gst"> file2 Therefore, each file contains 4 bytes. Here is the program (it will not compile as is because it contains a question mark): /* problem7.c */ #include <unistd.h> int main(void) { } char buffer = 'W'; open("file1", 2); open ("file2", 2); lseek (3, ?,1); write(3, &buffer, 1); lseek (4, -2, 2); write(4, &buffer, 1); read (0, &buffer, 1); write(4, &buffer, 1); lseek (3,-3, 2); write(3, &buffer, 1); gxWx write(4,"\n",1); lseek (4,1, 0); write(4, &buffer, 1); close (3); close (4); Without a further header file compilation will produce a warning, but this will not affect this problem. When you enter a certain character and the single question mark is replaced with an appropriate number cat file1 produces: gxi and cat file2 produces: What is that number and what is that character? The single question mark (?) should be replaced with: After the program starts you should enter the character: Save
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY