Copy of Topic03_System

pdf

School

University of Massachusetts, Amherst *

*We aren’t endorsed by this school

Course

230

Subject

Information Systems

Date

Dec 6, 2023

Type

pdf

Pages

4

Uploaded by UltraLobster3715

Report
Working with Linux System Forming Group Start time: 2:30 In this activity, you work in teams of 2~3 students to learn new programming concepts. Content Learning Objectives 1. Know how to use commands in Linux systems. 2. Identify the permission bits in Linux file systems. 3. Understand the file offset and file descriptor table. 4. Explore system calls in Linux systems. Role Name Project Manager : reads the questions aloud, keeps track of time and makes sure everyone contributes appropriately. 1. Clicks on FILE-> MAKE A COPY 2. Shares the copy with all the other team members using their UMass email address Vrishabh Recorder : records all answers in the Google doc shared by the Manager and ensures the team agrees on responses. Joshua Hacker : type the code and execute. Connor (25 min) Activity 1. Files Start time: 2:30 Consider the following code: #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
int main ( void ) { int fd1 = open( "file.txt" , O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); int fd2 = dup(fd1); int fd3 = open( "file.txt" , O_RDWR); write(fd1, "Hello," , 6 ); write(fd2, "world" , 5 ); lseek(fd2, 0 , SEEK_SET); write(fd1, "HELLO," , 6 ); write(fd3, "Gidday" , 6 ); lseek(fd1, -2 , SEEK_CUR); write(fd2, "OK" , 2 ); close(fd1); close(fd2); close(fd3); return 0 ; } Q1. After each of the calls to write () in the code above, explain what the content of the output file would be and why? Using the concept of three tables (file descriptor table, open file table, and i-node table) to explain. Answer: After first write(), then output file contains “Hello,”. Fd1 and fd2 have different file descriptor tables and same open file description while fd3 has its own file descriptor and open file description, and they all point to the same file in the i-node table. After second write, output file contains “Hello,world” since fd1 and fd2 share open file table so offset is updated for fd2. After third wite(), file contains “HELLO,world” since fd1 share offset with fd2 so it return back to 0. After fourth write(), output file contains “Giddayworld” since fd3 has its own offset so it start back at 0. After fifth write, output file contains “GiddOKworld”. Since fd2 and fd1 share offset so now fd2 starts at 4 again. Q2. After the last write system call, if we add write(fd3, "ok" , 3) ; before the close system calls. What would the content of the output file be and why is it somewhat unusual? Type command cat -v file.txt to check the content for invisible characters. Answer: “GiddOKok^@ld” It is unusual because it replaces part of the string with an invisible character.
(15 min) Activity 2. Linux Commands Start time: 2:44 Q3. From the terminal in the edlab machine, navigate to a directory with files in it and run the command " ls -l " , how do you know the permissions of the files that are listed? What are the permissions? Include a screenshot of your terminal along with your answer below. Answer: The first character is the directory, - for file, d for directory. All 3 are files. The next three characters are read, write, execute permissions. For two there are read and write (..rw-..), for test there is read, write, execute(..rwx..). All of these are permissions for the owner of the file. Next three characters are group permissions, and last three are permissions for everybody else. Q4. Create a simple "hello world" C program and compile it with gcc . What is the difference between the permissions of the source code and the compiled a.out binary file? Who has access and how does it differ? Include a screenshot of your terminal along with your answer below. Answer: The difference between the a.out file and the helloworld C program is that the program allows read and write for the owner and read for the group permission, while the a.out file also allows execution for both owner and group permissions. Q5. Run the ps command. Which processes are running under the bash shell that you are using? Include a screenshot of your terminal along with your answer below.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Answer: There are two processes running, one activated by bash and one by ps. Showing both ids. Good job! You have worked with Linux System Create a pdf of this worksheet file and upload it in Gradescope. There is no need to upload the C files.