PART-1
Linux Commands
Find out the commands for performing the following tasks in Linux OS, start a command shell and execute them at the command-line interface. You may use command line options with a command as needed. Information about a command and its options can be found in Linux by referring to lớn the manual pages: man command name. The assignment is to lớn be partly completed in the class and partly at trang chính.
Submit a report containing all print screen of all your work
Some General Commands
Print out your user name.
Clear the screen.
Exiting the command shell.
Changing the password.
File and Directory Commands
Create a directory by the name tmp in your current directory i.e. trang chính directory.
Change your current directory to lớn tmp.
Print your current directory path.
From your current directory which is tmp, go to lớn the parent directory.
Using an editor create a new text tệp tin, type in some text in it and save it as myfile.txt in your trang chính directory.
List the files in the directory. Notice the new tệp tin myfile.txt which you created with the editor.
List the files in the directory in the long format.
Make a copy of the tệp tin myfile.txt named newfile1.txt in the same directory.
Make a copy of the tệp tin myfile.txt in the directory tmp and điện thoại tư vấn it newfile2.txt. Check that the copy has been created by going into tmp and displaying the files in it. Then go back to lớn the parent directory.
Move the two txt files from your current trang chính directory into the tmp directory. Check that they have moved by displaying the contents of the current directory.
Go to lớn into the tmp directory. Display the contents of this directory. There should be three files in this directory.
Rename myfile.txt as newfile3.txt.
Display the contents of newfile1.txt.
Display the contents of newfile1.txt one page at a time. If the tệp tin is small i.e. less than vãn a page this command will have the same effect as the command in (m).
Delete the tệp tin newfile1.txt.
Delete the remaining two files in the directory with one command.
Go up into the parent directory and delete the directory tmp.
System Informational Commands
Print the current time and date.
Print the calendar of the current month.
Display the CPU information.
Display the memory information.
Display the list of current processes.
Display the list of all the current processes.
Some More Exercises
Create a tệp tin a1.txt. Execute the following commands and analyse the results:
cat a1.txt
cat a1.txt > result.txt
cat result.txt
cat a1.txt >> result.txt
cat result.txt
ls >> result.txt
cat result.txt
Display first few lines of a tệp tin.
Display last few lines of a tệp tin.
Operating Systems (CS 330)
PART-2
High-Level, Assembly and Machine Languages
In this assignment you will explore assembly and machine languages. You already know that when a high-level language program is compiled a machine language program gets generated that can be directly executed. What does such a machine language program look like? How can an .exe tệp tin be viewed and modified?
As a first step you will first write a simple C program to lớn add two integers and compile it with gcc (GNU C compiler). As an example, the following is the “Hello World” program in C. You can modify it to lớn make it add two integers.
#include
#include
int main(int argc, char **argv){
printf("Hello World of C");
}
The compilation command in Linux would be: gcc –o HelloWorld HelloWorld.c assuming that this program is saved in the tệp tin HelloWorld.c .
The compiler gcc has an option to lớn generate the compiled code is assembly language. Find out how such an option can be used and use it to lớn generate assembly language code for your high-level program for adding two integers. View this tệp tin and note the point where the two numbers get added in assembly. You may also use the Linux utility: objdump –d exe tệp tin name, to lớn disassemble the exe tệp tin into assembly and see the instruction for adding the two numbers.
Next, edit the executable tệp tin generated by gcc in step (a), to lớn change the addition operation to lớn a subtraction operation. You will have to lớn bởi some research here to lớn find out the op code for subtraction instruction and other issues. (Use editors available freely online for editing executable files and other binary files for this purpose. One such editor is hexedit, but it would be best that you tìm kiếm online for a better option.) After modifying the code try to lớn run rẩy the executable to lớn see if you have succeeded. If not try to lớn explain why you failed.
Java compiler, javac, compiles Java language files to lớn java byte code (not the machine language instructions) which is executed by the Java Virtual Machine (JVM). Try to lớn find out how a Java byte code tệp tin can be viewed. Can source files be generated for Java byte code?
- PART-3
What will be the output of the following code segment
int value = 3;
int main() {
pid t pid;
pid = fork();
if (pid == 0) {
value += 9;
printf("value at A = %d", value);
return 0;
}
else if (pid > 0) {
wait(NULL);
printf("value at B = %d", value);
return 0;
}
}
What will be the values printed at lines A and B? Assume that the actual process ids (pids) of the parent and child are 2300 and 2304, respectively
int main(){
pid_t pid;
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
elseif (pid == 0) {
pid = getpid();
printf("At A: pid = %d", pid); /* A */ }
else (pid > 0){
printf("At B: pid = %d", pid); /* B */
wait(NULL);
}
return 0;
Given the below C program, including the parent process, how many processes are created? Draw the processes tree.
int main(void) {
for (i=1; i<=2; i++){
fork();
}
fork();
return 0;
}
Suppose a program has three threads Thread-1, Thread-2 and Thread-3 and a shared counter count as shown below. State all possible output and give a complete elaboration of your finding.
Semaphore S = 1; int count = 7;
Thread 1 |
Thread 2 |
Thread 3 |
Thread_1(){ wait(S); count++; signal(S); } |
Thread_2(){ wait(S); count--; signal(S); } |
Thread_3(){ wait(S); printf(count); signal(S); } |