sharif-os-lab / session-3-4 Goto Github PK
View Code? Open in Web Editor NEWمستندات آزمایش سوم و چهارم درس آزمایشگاه سیستم عامل
License: MIT License
مستندات آزمایش سوم و چهارم درس آزمایشگاه سیستم عامل
License: MIT License
Team Name: [FILL HERE]
Student Name of member 1: [FILL HERE]
Student No. of member 1: [FILL HERE]
Student Name of member 2: [FILL HERE]
Student No. of member 2: [FILL HERE]
[FILL HERE with an image of files in /proc/ directories. Use ls command.]
[FILL HERE with the content of /proc/version. Use cat command.]
[FILL HERE with the content of two files with non-numeric name other thatn /proc/version.]
[FILL HERE with the program you write for this part (see experiment guide for information).]
[FILL HERE with screen capture from your programs execution.]
[FILL HERE with description about, what happens if you try to write a sentence in to /proc/version.]
Write (in English or Persian) about each file in /proc/(PID) directory:
[FILL HERE with description about cmdline]
[FILL HERE with description about environ]
[FILL HERE with description about stat]
[FILL HERE with description about status]
[FILL HERE with description about statm]
[FILL HERE with description about cwd]
[FILL HERE with description about exe]
[FILL HERE with description about root]
Place your script for shwoing PID of running porcesses and their name here:
[FILL HERE with you script]
Place your source code for a program that shows details of a program by receiving PID:
[FILL HERE with you source code]
Write (in English or Persian) about each file in /proc/ directory:
meminfo/version/uptime/stat/mount/net/loadavg/
interrupts/ioports/filesystem/cpuinfo/cmdline
[FILL HERE with description about meminfo]
[FILL HERE with description about version]
[FILL HERE with description about uptime]
[FILL HERE with description about stat]
[FILL HERE with description about mount]
[FILL HERE with description about net directory (or file)]
[FILL HERE with description about loadavg]
[FILL HERE with description about interrupts]
[FILL HERE with description about ioports]
[FILL HERE with description about filesystem]
[FILL HERE with description about cpuinfo]
[FILL HERE with description about cmdline]
Place your source code for a program that shows details of processor:
[FILL HERE with you source code]
Place your source code for a program that shows details of memory management sub-system:
[FILL HERE with you source code]
Write your description about five important files at /proc/sys/kernel:
[FILL HERE with you descript for 1st file]
[FILL HERE with you descript for 2nd file]
[FILL HERE with you descript for 3rd file]
[FILL HERE with you descript for 4th file]
[FILL HERE with you descript for 5th file]
Write your description about /proc/self file
[FILL HERE with you description]
Team Name: [FILL HERE]
Student Name of member 1: [FILL HERE]
Student No. of member 1: [FILL HERE]
Student Name of member 2: [FILL HERE]
Student No. of member 2: [FILL HERE]
Investigate the ps command
[FILL HERE with an image of ps command showing running processes.]
Infromation about processes with PID = 1
[FILL HERE with description.]
Program using getpid
[FILL HERE with your program code.]
Program using getppid
[FILL HERE with your program code.]
[FILL HERE with descriptions about the parent process]
[FILL HERE with an image of the program execution]
Describe the C program (fork program)
[FILL HERE with descriptions]
Program showing that memory of the parent and the child is seperate
[FILL HERE with your source code]
Program printing different messages for parent and child process
[FILL HERE with your source code]
Program for the last task of this section
[FILL HERE with your source code]
[FILL HERE with you description of the output
] Program using wait
and counting from 1 to 100
[FILL HERE with your source code]
[FILL HERE about description for the parameter of wait system call]
Program showing process adoption
[FILL HERE with your source code]
[FILL HERE an image from execution of your program]
Describe following commands/APIs:
[FILL HERE with description about execv]
[FILL HERE with description about execl]
[FILL HERE with description about execvp]
[FILL HERE with description about execlp]
Program which forks and executues ls
command
[FILL HERE with your source code]
[FILL HERE an image from execution of your program]
Team Name: [97110788-97107245]
Student Name of member 1: Alireza Isavand
Student No. of member 1: 97110788
Student Name of member 2: Mehregan Mohseni
Student No. of member 2: 97107245
[FILL HERE with an image of ps command showing running processes.]
Infromation about processes with PID = 1
[FILL HERE with description.]
پردازه systemd یا init، اولین پردازه ساخته شده در لینوکس می باشد
این پردازه به طور کلی وظیفه مدیریت سیستم و سرویس های آن را بر عهده دارد.
هدف اصلی این پردازه، پیکربندی کردن سرویس های هسته لینوکس در بین توزیع های مختلف است.
همچنین این پردازه سرویس هایی برای راه اندازی و مدیریت فضای کاربر در هنگام بوت شدن سیستم شروع می کند.
هنگام بوت شدن سیستم عامل، مولفه های این پردازه از چندین فایل متنی ساخته می شود
(به عنوان مثال در مسیر /etc/systemd/system)
سپس این پردازه شروع به بالا آوردن سرویس ها و پردازه های دیگر می کند
Program using getpid
[FILL HERE with your program code.]
Program using getppid
[FILL HERE with your program code.]
[FILL HERE with descriptions about the parent process]
[FILL HERE with an image of the program execution]
Describe the C program (fork program)
[FILL HERE with descriptions]
Program showing that memory of the parent and the child is seperate
[FILL HERE with your source code]
Program printing different messages for parent and child process
[FILL HERE with your source code]
Program for the last task of this section
[FILL HERE with your source code]
[FILL HERE with you description of the output
] Program using wait
and counting from 1 to 100
[FILL HERE with your source code]
[FILL HERE about description for the parameter of wait system call]
Program showing process adoption
[FILL HERE with your source code]
[FILL HERE an image from execution of your program]
Describe following commands/APIs:
[FILL HERE with description about execv]
[FILL HERE with description about execl]
[FILL HERE with description about execvp]
[FILL HERE with description about execlp]
Program which forks and executues ls
command
[FILL HERE with your source code]
[FILL HERE an image from execution of your program]
please submit all your codes in a zip file
Zip File HERE
Team Name: 96150292-96150127
Student Name of member 1: Laaya Yaghoubi
Student No. of member 1: 96150292
Student Name of member 2: Shayan Masrour
Student No. of member 2: 96150127
Investigate the ps command
Infromation about processes with PID = 1
Program using getpid
int main(void)
{
pid_t result = fork();
printf("\nfork result %d", result);
printf("\nI am after forking\n");
printf("\nIam process %d", getpid());
printf("\nI am parent process %d", getppid());
return 0;
}
1. [ ]A parent process is one that creates a child process using a fork() system call. A parent process may have multiple child processes, but a child process only one parent process. On the success of a fork() system call: The Process ID (PID) of the child process is returned to the parent process.
1. [ ]
Describe the C program (fork program)
Program showing that memory of the parent and the child is seperate
#define MAX_COUNT 200
void ChildProcess(void); /* child process prototype /
void ParentProcess(void); / parent process prototype */
void main(void)
{
pid_t pid;
pid = fork();
if (pid == 0)
ChildProcess();
else
ParentProcess();
}
void ChildProcess(void)
{
int i;
for (i = 1; i <= MAX_COUNT; i++)
printf(" This line is from child, value = %d\n", i);
printf(" * Child process is done *\n");
}
void ParentProcess(void)
{
int i;
for (i = 1; i <= MAX_COUNT; i++)
printf("This line is from parent, value = %d\n", i);
printf("* Parent is done *\n");
}
When the main program executes fork(), an identical copy of its address space, including the program and all data, is created. System call fork() returns the child process ID to the parent and returns 0 to the child process. The following figure shows that in both address spaces there is a variable pid. The one in the parent receives the child's process ID 3456 and the one in the child receives 0.
int main(void)
{
pid_t pid;
printf("I am the parent process & pid is:%d.\n",getpid());
printf("before forking\n");
pid = fork();
pritnf("after forking\n");
if(pid == 0)
{
printf("i am the child process and pid is:%d.\n", getpid());
}
else if (pid>0)
{
printf("i am the parent process and pid is: %d.\n", getpid());
}
else if (pid == -1)
{
printf("Error fork failed\n");
}
return 0;
}
int main(void)
{
pid_t pid;
printf("before forking\n");
printf("I am the parent process & pid is:%d.\n",getpid());
pid = fork();
printf("after first forking\n");
if(pid == 0)
{
printf("i am the child process and pid is:%d.\n", getpid());
}
else if (pid>0)
{
printf("i am the parent process and pid is: %d.\n", getpid());
}
else if (pid == -1)
{
printf("Error fork failed\n");
}
pid = fork();
printf("after second forking\n");
if(pid == 0)
{
printf("i am the child process and pid is:%d.\n", getpid());
}
else if (pid>0)
{
printf("i am the parent process and pid is: %d.\n", getpid());
}
else if (pid == -1)
{
printf("Error fork failed\n");
}
return 0;
}
1. [ ] In Linux, a daemon is typically created by forking twice with the intermediate process exiting after forking the grandchild. This has the effect of orphaning the grandchild process. As a result, it becomes the responsibility of the OS to clean up after it if it terminates. The reason has to do with what are known as zombie processes which continue to live and consume resources after exiting because their parent, who'd normally be responsible for the cleaning up, has also died.
wait
and counting from 1 to 100
int main()
{
int ret = fork();
if(ret == 0) {
int i;
for(i=1; i<=100; i++)
{
printf("THIS LINE IS FROM CHILD, value = %d\n", i);
printf("\nchild process is done\n")
}
}
else{
int rc = 0;
wait(&rc);
printf("return code is %d\n",WEXITSTATUS(rc));
int i;
for(i=1; i<=100; i++)
{
printf("THIS LINE IS FROM PARENT, value = %d\n", i);
printf("\nchild process is done\n")
}
}
return 0;
}
1. [ ] All of these system calls are used to wait for state changes in a
child of the calling process, and obtain information about the child
whose state has changed. A state change is considered to be: the
child terminated; the child was stopped by a signal; or the child was
resumed by a signal. In the case of a terminated child, performing a
wait allows the system to release the resources associated with the
child; if a wait is not performed, then the terminated child remains
in a "zombie" state.
If a child has already changed state, then these calls return immedi‐
ately. Otherwise, they block until either a child changes state or a
signal handler interrupts the call (assuming that system calls are not
automatically restarted using the SA_RESTART flag of sigaction(2)).
In the remainder of this page, a child whose state has changed and
which has not yet been waited upon by one of these system calls is
termed waitable.
int main()
{
pid_t pid;
printf("i am the original process with PID %d and PPID %d.\n", getpid(),getppid());
pid = fork();
if (pid> 0)
{
printf("i am the parent with PID %d and PPID%d.\n", getpid(),getppid());
printf("my child's PID is %d\n", pid);
}
else if (pid ==0)
{
sleep(4);
printf("i'm the child with PID %d and PPID %d.\n", getpid(),getppid());
}
printf("PID %d terminates.\n", getpid());
printf("PID %d terminates.\n", getppid());
}
1.
Describe following commands/APIs:
Program which forks and executues ls
command
please submit all your codes in a zip file
Team Name: 97110788-97107245
Student Name of member 1: Alireza Isavand
Student No. of member 1: 97110788
Student Name of member 2: Mehregan Mohseni
Student No. of member 2: 97107245
Do 5 subtasks from 1 to 5:
1. [FILL HERE with the content of /proc/version. Use cat command.]
Here we have linux kernel version, username of installer, gcc version, debian version of where gcc is installed and kernel compile date.
2. [FILL HERE with the content of two files with non-numeric name other thatn /proc/version.]
proc/partitions: Partitioned devices are listed in dir: /dev/ . In proc/partitions we have their information such as major and minor number which are related to devicetype and identification number. And also their number of blocks.
proc/uptime: It shows two numbers. The first one is the total seconds that the machine is on since its last poweroff/reboot. The second number is the total time that all cores have spent the idle process. It can be greater than the first number with multiple cores.
3. [FILL HERE with the program you write for this part (see experiment guide for information).]
#include <iostream>
#include <fstream>
using namespace std;
int main(){
string line;
ifstream ini_file;
ini_file.open("/proc/version");
ofstream out_file;
out_file.open("linux_version.txt");
if (ini_file && out_file) {
while(getline(ini_file, line)){
out_file << line << "\n";
}
}
ini_file.close();
out_file.close();
return 0;
}
4. [FILL HERE with screen capture from your programs execution.]
5. [FILL HERE with description about, what happens if you try to write a sentence in to /proc/version.]
Permission denied. We do not have the "Write" access for this file. Only root user can write on this file.
Write (in English or Persian) about each file in /proc/(PID) directory:
Place your script for shwoing PID of running porcesses and their name here:
[FILL HERE with your script]
pstree -cp
ps -aux
Place your source code for a program that shows details of a program by receiving PID:
[FILL HERE with your source code]
#include <cstdio>
#include <cstdlib>
using namespace std;
int main() {
string s;
cin >> s;
string cmd = "cat /proc/" + s + "/cmdline";
const char* str = &cmd[0u];
system(str);
cmd = "cat /proc/" + s + "/environ";
str = &cmd[0u];
system(str);
cmd = "`cut -d \' \' -f1 /proc/" + s + "/statm`";
str = &cmd[0u];
system(str);
cmd = "cat /proc/" + s + "/status";
str = &cmd[0u];
system(str);
return 0;
}
Write (in English or Persian) about each file in /proc/ directory:
Place your source code for a program that shows details of processor:
[FILL HERE with your source code]
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream myReadFile;
myReadFile.open("/proc/cpuinfo");
string output;
string str = "";
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
myReadFile >> output;
str += output + " ";
}
}
myReadFile.close();
if (str.find("cache size"))
{
int idx = str.find("cache size");
int i = 0;
while(i < 20) {
cout << str[idx + i];
i++;
}
cout << "B" << endl;
}
if (str.find("model name"))
{
int idx = str.find("model name");
int i = 0;
while(i < 54) {
cout << str[idx + i];
i++;
}
cout << endl;
}
if (str.find("cpu MHz"))
{
int idx = str.find("cpu MHz");
int i = 0;
while(i < 18) {
cout << str[idx + i];
i++;
}
cout << endl;
}
}
Place your source code for a program that shows details of memory management sub-system:
[FILL HERE with your source code]
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream myReadFile;
myReadFile.open("/proc/meminfo");
string output;
string str = "";
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
myReadFile >> output;
str += output + " ";
}
}
myReadFile.close();
for (int i = 0; i < str.size() - 7; i++)
{
if (str[i] == 'M' && str[i+1] == 'e' && str[i+2] == 'm' && str[i+3] == 'T' && str[i+4] == 'o' && str[i+5] == 't' && str[i+6] == 'a' && str[i+7] == 'l')
{
int s = i;
while(str[s] != 'B'){
cout<<str[s];
s++;
}
cout<<"B"<<endl;
}
}
for (int i = 0; i < str.size() - 6; i++)
{
if (str[i] == 'M' && str[i+1] == 'e' && str[i+2] == 'm' && str[i+3] == 'F' && str[i+4] == 'r' && str[i+5] == 'e' && str[i+6] == 'e')
{
int s = i;
while(str[s] != 'B'){
cout<<str[s];
s++;
}
cout<<"B"<<endl;
}
}
for (int i = 0; i < str.size() - 5; i++)
{
if (str[i] == 'A' && str[i+1] == 'c' && str[i+2] == 't' && str[i+3] == 'i' && str[i+4] == 'v' && str[i+5] == 'e' && str[i+6] != '(')
{
int s = i;
while(str[s] != 'B'){
cout<<str[s];
s++;
}
cout<<"B"<<endl;
}
}
}
Write your description about five important files at /proc/sys/kernel:
Write your description about /proc/self file
[FILL HERE with your description]
please submit all your codes in a zip file
Zip File HERE
Team Name: 97103208-97110025
Student Name of member 1: Alireza Hasanpour
Student No. of member 1: 97103208
Student Name of member 2: Kian Bakhtari
Student No. of member 2: 97110025
[FILL HERE with an image of ps command showing running processes.]
Information about processes with PID = 1
[systemd is a system and service manager for Linux operating systems. When run as first process on boot (as PID 1) it acts as init system that brings up and maintains userspace service. For compatibility with SysV, if systemd is called as init and a PID that is not 1, it will execute telinit and pass all command line arguments unmodified. That means init and telinit are mostly equivalent when invoked from normal login sessions. ]
Program using getpid
#include <iostream>
#include <unistd.h>
using namespace std;
int main(){
int pid = fork();
if (pid == 0) cout << getpid();
return 0;
}
#include <iostream>
#include <unistd.h>
using namespace std;
int main(){
int pid = fork();
if (pid == 0) cout << getppid();
return 0;
}
Describe the C program (fork program)
Program showing that the memory of the parent and the child is separate
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
int main() {
int check = 10;
int ret = fork();
if (ret == 0) {
check = 5;
printf("Child check = %d\n", check);
} else {
sleep(5);
printf("Parent check = %d\n", check);
}
return 0;
}
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
int main() {
int check = 10;
int ret = fork();
if (ret == 0) {
check = 5;
printf("This is child process");
} else {
sleep(5);
printf("This is parent process");
}
return 0;
}
1. [ ] There are PIDs from 711 to 718 which means there are 8 processes. This is because we forked three times
and with each fork, the processes are doubled. Thus, the number of processes will be equal to 2^3 = 8.
Program using wait
and counting from 1 to 100
Program showing process adoption
1. [ ]
Describe the following commands/APIs:
Program which forks and executues ls
command
1. [ ]
please submit all your codes in a zip file
Zip File HERE
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.