Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Compare and contrast hello_c.txt and hello_cpp.txt, and answer the following que

ID: 3591609 • Letter: C

Question

Compare and contrast hello_c.txt and hello_cpp.txt, and answer the following questions:

2.1 Did they use any different system calls?

2.2 Was there any difference in terms of the number of times system calls used?

2.3 What can you say about the two hello programs of the same functionality in terms of their efficiency in using system resources?

hello_c.txt:

First, write a C program, called "hello.c", which prints "Hello from !" in the user mode. (Be careful not to use any C++ features in your code.) Replace in the messages by your first and last name. Make sure that a new- line character is inserted after the message.

Compile your program using the following command: $ gcc -Wall -ansi hello.c -o hello_c

The command will generate the "hello_c" executable file. You need to resolve any errors or warnings.

You can verify if the program works properly by executing it: $ ./hello_c

Invoke the following command to trace the system calls and signals that are used by your program: $ strace ./hello_c >& hello_c.txt

The command will save the output of strace to hello_c.txt. Each line of the output describes a system call.

hello_cpp.txt:

Second, write a similar hello world program in C++ this time (called hello.cpp). Don't forget to insert a new-line character at the end of the message.

Compile hello.cpp and run strace accordingly:

$ g++ -Wall -ansi hello.cpp -o hello_cpp

$ strace ./hello_cpp >& hello_cpp.txt

Explanation / Answer

Answers:

2.1: NO, they will not use different system calls.

System call used by hello.c and hello.cpp are: execve(),brk(),access(),mmap(),open(),fstat(),close(),read(),mprotect(),exit_group(),write(),munmap(),arch_prctl1()

For hello.c: execve() --> 1,

brk()-->3,access()-->3,mmap()-->8,open()-->2,fstat()-->3,close()-->2,read()-->1,mprotect()-->4,exit_group()-->1,write()-->1,munmap()-->1

For hello.c: execve() --> 1,,arch_prctl1()-->1

brk()-->3,access()-->3,mmap()-->8,open()-->2,fstat()-->3,close()-->2,read()-->1,mprotect()-->4,exit_group()-->1,write()-->1,munmap()-->1

2.2 YES, there is difference in number of times a system call is used.

For hello.c: execve() --> 1,

brk()-->3,access()-->3,mmap()-->8,open()-->2,fstat()-->3,close()-->2,read()-->1,mprotect()-->4,exit_group()-->1,write()-->1,munmap()-->1

For hello.cpp: execve() --> 1,

brk()-->3,access()-->4,mmap()-->8,open()-->4,fstat()-->6,close()-->5,read()-->3,mprotect()-->9,exit_group()-->1,write()-->1,munmap()-->1

2.3 First program hello.c is more efficient than hello.cpp because it uses less memory and less time than the hello.cpp.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote