0% found this document useful (0 votes)
31 views3 pages

Lab1 Official

Uploaded by

chiller
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

Lab1 Official

Uploaded by

chiller
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Learning outcome

To use, study, and manipulate some operations on Ubuntu OS.


To use the gcc compiler, then compile them to the OS concept

Requirements
Ubuntu operating system (OS) or any Linux-similar OSs should be installed on
your laptop.
Ubuntu OS should contain gcc compiler to compile C programs. If your Ubuntu
OS has not been installed gcc yet, please install it.
Every exercise should be done on terminal of Ubuntu OS.
Every screenshots should contain username (your student ID or the username of
your FPT email).
Laboratory exercises
For all exercises, please replace the term YourStudentID by your student ID.
1. Using a command to show the current date (today).
Check the current folder.
Create the folder Lab1_YourStudentID.
Then check what folders are there in home directory?
2. a. At the folder Lab1_YourStudentID, create a file-and-folder system to manage
members’ information of a university.
a. Create a folder “University_YourStudentID”
b. Inside above folder, create two subfolders “Depart1_YourStudentID” and
“Depart2_YourStudentID”
c. Use a text editor (vim or nano) to create a file “members_YourStudentID.txt”,
inside the folder “Depart2_YourStudentID”, to contain three names
“Nguyen Le A
Le Huynh B
Huynh Nguyen C”
Then save the content and exit the editor.
d. Copy this file to folder Depart1_YourStudentID and rename to
members_YourStudentID_cp.txt. The number of the commands is as short as
possible.
e. Use sed command to replace Nguyen by YourStudentID in file
members_YourStudentID_cp.txt
After finish replacing, please use cat command to show the content of
members_YourStudentID_cp.txt
3. Run this command in the terminal: sudo ps -U username
Describe the result.
4. At the folder Lab1_YourStudentID, create a folder “Program1_
YourStudentID”.
Then inside this folder, create a file YourStudentID_demo1.c and contain the C
program as follow:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(){
printf("this is the first time of YourStudentID\n");
fork();
printf("this is the second time of YourStudentID\n");
fork();
printf("this is the final time of YourStudentID\n");
return 0;
}
Please take a screenshot of the editor you are using to create a file containing C
program. Hint: you can use vim or nano editors or any editor with which you get
familiar to create a new file as long as it MUST run via OS’s terminal (no GUI
editor).
c. After you save it and exit editor, please take a screenshot showing the contents
of the file you have created on terminal screen. Hint: cat command.
d. Use gcc compiler to compile the C-program file that you have created. Then
execute it. Finally, explain the result.
5. At the folder Lab1_YourStudentID, create a folder “Program2_
YourStudentID”.
Then inside this folder, create a file YourStudentID_demo2.c and contain the C
program as follow:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(){
int pid;
printf("This is the process created by main function\n");
pid = fork();
if (pid != 0){
printf("this is the x process with ID of %d\n", getpid());
} else {
printf("this is the y process with ID of %d\n", getpid());
}
return 0;
}
Then save the content and exit editor.
Use gcc compiler to compile it, then execute it.
How is the output? x process is the parent process or child process; y process is
parent process or child process. Please explain your choice.
You have to take the screenshots similar to exercise 4 for your report.

Submission
Please submit PDF file (your report) and ZIP file (contains the programs, files and
folders you have created). Any other types of files will NOT be accepted for
grading.
Remind: please remember the condition of PLAGIARISM that we have agreed at
the beginning of the course.

You might also like