Docsity

Operating Systems and System Programming Homework Solutions, Appunti di Sistemi Operativi

Toggle sidebar
bg1
Operating systems and system programming CF − VS − RS
Homework 1
Exercice 1
Text
Build the following directory tree:
A
D C
G
H
B
F
I
E
modify permissions of directories in order that:
1. everybody can read and write in a;
2. nobody can create subdirectories of d;
3. others can not see inside c, but can create brothers of g;
4. others can enter in g, but not in h;
5. group can not see g (visualize what is inside g), but can enter in h;
6. others has no rights on b, while group has all permissions;
7. owner can read i, but has no other rights on i.
Create a file xyz in a (using touch command) and modify permissions in
order that only the owner can read and write on the file.
Solution
Directories are create with the following commands:
1mk di r a
2cd a
3mk di r b
4mk di r c
5mk di r d
6cd c
7mk di r g
1
pf3
pf4
pf5

Anteprima parziale del testo

Scarica Operating Systems and System Programming Homework Solutions e più Appunti in PDF di Sistemi Operativi solo su Docsity!

Homework 1

Exercice 1

Text

Build the following directory tree:

A

D C

G

H

B

F

I

E

modify permissions of directories in order that:

1. everybody can read and write in a;

2. nobody can create subdirectories of d;

3. others can not see inside c, but can create brothers of g;

4. others can enter in g, but not in h;

5. group can not see g (visualize what is inside g), but can enter in h;

6. others has no rights on b, while group has all permissions;

7. owner can read i, but has no other rights on i.

Create a file xyz in a (using touch command) and modify permissions in

order that only the owner can read and write on the file.

Solution

Directories are create with the following commands:

1 mkdir a 2 cd a 3 mkdir b 4 mkdir c 5 mkdir d 6 cd c 7 mkdir g

8 cd g 9 mkdir h 10 cd .. 11 cd .. 12 cd b 13 mkdir e 14 mkdir f 15 cd f 16 mkdir i

Permissions - directory

1. chmod 777 a;

2. chmod 555 d;

3. chmod 772 c;

4. chmod 770 h;

5. chmod 717 g;

6. chmod 770 b;

7. chmod 477 i.

1 cd a

2 touch xyz - c r e a t e the file

3 ls - check if file exist

4 chmod 600 xyz

5 ls - la - check permission

Exercice 2

Text

Verify with which permissions files and directories are usually created. Then,

using umask command, try to have these files created readable and writable

from everyone. Try to have these files readable and writable only from the

user.

Solution

Fist of all a file need to be created:

1 touch bbb

With the command ls -al is possible to verify default permissions; they are:

Homework 2

Exercice 1

Text

Show a list of all files called “core” in all the file system. Do not visualize

error messages.

Solution

This work can be done easly with the following command:

1 find / - name ’* core * ’ - print 2 > error. txt

The most important thing to remember is that 2> send all errors retreived

by the stderr to the file error.txt.

In order to check if the command worked it is possible to open that file

with any kind of text editor; using gedit:

1 gedit error. txt

This command shows how many errors are present.

Exercice 2

Text

Show a list of all processes of root user. The list must have the following

format:

PID %CPU Command

Solution

There are at least two solutions for this problem. The first one is:

1 ps -u root - eo pid - eo pcpu - eo com

The second one is a bit more difficult since it is required to parse the entire

content in this way:

1 ps - el | sed ’s /\ s +/\ t / g ’ | cut -f 4 ,6 ,

Exercice 3

Text

Create 15 empty files called [ xxx1, xxx2, xxx3 , ..... , xxx15]. Show the

list of the previously created file names both in ascending and descending

order. Save the list in a file called list.txt.

Solution

First of all files have to be created in a directory:

1 mkdir test 2 touch file 3 touch file 4 touch file 5 touch file 6 touch file 7 touch file 8 touch file 9 touch file 10 touch file 11 touch file 12 touch file 13 touch file 14 touch file 15 touch file 16 touch file

In order to do this, it is also possible create a script, but since now it is not

necessary: the previous way it is more simple and effective.

The second step is order them in an ascending order and save that list

into a file; it is required only a command:

1 ls | sort -n > list_ascending_order. txt

Instead, to have a list of them in a descending order is sufficient change the

option -n into -r:

1 ls | sort -r > list_descending_order. txt Exercice 4

Text

Find all the directories of your home whose name ends with the string backup

(eventually create some of them) and move them in a backup directory.

Solution

This problem can be solved with the following command: