Git Product home page Git Product logo

session-3-4's People

Contributors

alitavassoly avatar amirhossein1376 avatar fshahinfar1 avatar hamidrezash2000 avatar mahdiplj avatar parsa2820 avatar soleyman79 avatar

Stargazers

 avatar

Watchers

 avatar

session-3-4's Issues

DO NOT OPEN YOUR REPORT ISSUE HERE, OPEN IN YOUR PRIVATE REPO

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]

  • Read Session Contents.

Section 3.3.1

  • Investigate the /proc/ directory
    1. [FILL HERE with an image of files in /proc/ directories. Use ls command.]

Section 3.3.2

  • Do 5 subtasks from 1 to 5:
    1. [FILL HERE with the content of /proc/version. Use cat command.]
    2. [FILL HERE with the content of two files with non-numeric name other thatn /proc/version.]
    3. [FILL HERE with the program you write for this part (see experiment guide for information).]
    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.]

Section 3.3.3

  • Write (in English or Persian) about each file in /proc/(PID) directory:

    1. [FILL HERE with description about cmdline]
    2. [FILL HERE with description about environ]
    3. [FILL HERE with description about stat]
    4. [FILL HERE with description about status]
    5. [FILL HERE with description about statm]
    6. [FILL HERE with description about cwd]
    7. [FILL HERE with description about exe]
    8. [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]

Section 3.3.4

  • Write (in English or Persian) about each file in /proc/ directory:
    meminfo/version/uptime/stat/mount/net/loadavg/
    interrupts/ioports/filesystem/cpuinfo/cmdline

    1. [FILL HERE with description about meminfo]
    2. [FILL HERE with description about version]
    3. [FILL HERE with description about uptime]
    4. [FILL HERE with description about stat]
    5. [FILL HERE with description about mount]
    6. [FILL HERE with description about net directory (or file)]
    7. [FILL HERE with description about loadavg]
    8. [FILL HERE with description about interrupts]
    9. [FILL HERE with description about ioports]
    10. [FILL HERE with description about filesystem]
    11. [FILL HERE with description about cpuinfo]
    12. [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]

DO NOT OPEN YOUR REPORT ISSUE HERE, OPEN IN YOUR PRIVATE REPO

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]

  • Read Session Contents.

Section 4.4.1

  • Investigate the ps command

    1. [FILL HERE with an image of ps command showing running processes.]
  • Infromation about processes with PID = 1

    1. [FILL HERE with description.]
  • Program using getpid

    1. [FILL HERE with your program code.]

Section 4.4.2

  • Program using getppid

    1. [FILL HERE with your program code.]
    2. [FILL HERE with descriptions about the parent process]
    3. [FILL HERE with an image of the program execution]
  • Describe the C program (fork program)

    1. [FILL HERE with descriptions]
  • Program showing that memory of the parent and the child is seperate

    1. [FILL HERE with your source code]
  • Program printing different messages for parent and child process

    1. [FILL HERE with your source code]
  • Program for the last task of this section

    1. [FILL HERE with your source code]
    2. [FILL HERE with you description of the output]

Section 4.4.3

  • Program using wait and counting from 1 to 100

    1. [FILL HERE with your source code]
    2. [FILL HERE about description for the parameter of wait system call]
  • Program showing process adoption

    1. [FILL HERE with your source code]
    2. [FILL HERE an image from execution of your program]

Section 4.4.4

  • Describe following commands/APIs:

    1. [FILL HERE with description about execv]
    2. [FILL HERE with description about execl]
    3. [FILL HERE with description about execvp]
    4. [FILL HERE with description about execlp]
  • Program which forks and executues ls command

    1. [FILL HERE with your source code]
    2. [FILL HERE an image from execution of your program]

Session 4 Report

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

  • Read Session Contents.

Section 4.4.1

  • Investigate the ps command
    1. [FILL HERE with an image of ps command showing running processes.]

1

  • Infromation about processes with PID = 1

    1. [FILL HERE with description.]

    پردازه systemd یا init، اولین پردازه ساخته شده در لینوکس می باشد
    این پردازه به طور کلی وظیفه مدیریت سیستم و سرویس های آن را بر عهده دارد.
    هدف اصلی این پردازه، پیکربندی کردن سرویس های هسته لینوکس در بین توزیع های مختلف است.
    همچنین این پردازه سرویس هایی برای راه اندازی و مدیریت فضای کاربر در هنگام بوت شدن سیستم شروع می کند.

    هنگام بوت شدن سیستم عامل، مولفه های این پردازه از چندین فایل متنی ساخته می شود
    (به عنوان مثال در مسیر /etc/systemd/system)
    سپس این پردازه شروع به بالا آوردن سرویس ها و پردازه های دیگر می کند

  • Program using getpid

    1. [FILL HERE with your program code.]

Section 4.4.2

  • Program using getppid

    1. [FILL HERE with your program code.]
    2. [FILL HERE with descriptions about the parent process]
    3. [FILL HERE with an image of the program execution]
  • Describe the C program (fork program)

    1. [FILL HERE with descriptions]
  • Program showing that memory of the parent and the child is seperate

    1. [FILL HERE with your source code]
  • Program printing different messages for parent and child process

    1. [FILL HERE with your source code]
  • Program for the last task of this section

    1. [FILL HERE with your source code]
    2. [FILL HERE with you description of the output]

Section 4.4.3

  • Program using wait and counting from 1 to 100

    1. [FILL HERE with your source code]
    2. [FILL HERE about description for the parameter of wait system call]
  • Program showing process adoption

    1. [FILL HERE with your source code]
    2. [FILL HERE an image from execution of your program]

Section 4.4.4

  • Describe following commands/APIs:

    1. [FILL HERE with description about execv]
    2. [FILL HERE with description about execl]
    3. [FILL HERE with description about execvp]
    4. [FILL HERE with description about execlp]
  • Program which forks and executues ls command

    1. [FILL HERE with your source code]
    2. [FILL HERE an image from execution of your program]

Source Code Submission

please submit all your codes in a zip file

  • Zip File HERE

Session 4 Report

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

  • Read Session Contents.

Section 4.4.1

  • Investigate the ps command

    1. [ ]
      Screenshot 2021-11-05 172240
  • Infromation about processes with PID = 1

    1. Process ID 1 is usually the init process primarily responsible for starting and shutting down the system. Originally, process ID 1 was not specifically reserved for init by any technical measures: it simply had this ID as a natural consequence of being the first process invoked by the kernel.
      Screenshot 2021-11-05 180352
  • Program using getpid

    1. Screenshot 2021-11-05 180610

Section 4.4.2

  • Program using getppid
    1. #include <stido.h>
      #include <unistd.h>

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. [ ]Screenshot 2021-11-05 182809

  • Describe the C program (fork program)

    1. we fork and get a new process.
      we check if a process is the child (ret == 0) or if it is the parent (ret!= 0).
      In the child process you get 23.
  • Program showing that memory of the parent and the child is seperate

    1. #include <stdio.h>
      #include <sys/types.h>

#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.

  • Program printing different messages for parent and child process
    1. #include <stdio.h>
      #include <unistd.h>

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;
}
Screenshot 2021-11-05 194414

  • Program for the last task of this section
    1. #include <stdio.h>
      #include <unistd.h>

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;
}
Screenshot 2021-11-05 195726

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.

Section 4.4.3

  • Program using wait and counting from 1 to 100
    1. #include <stdio.h>
      #include <sys/wait.h>
      #include <unistd.h>

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;
}
Screenshot 2021-11-05 194655

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.
  • Program showing process adoption
    1. #include <stdio.h>
      #include <sys/wait.h>
      #include <stdlib.h>
      #include <unistd.h>

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.
Screenshot 2021-11-05 203848

Section 4.4.4

  • Describe following commands/APIs:

    1. The exec subroutine, in all its forms, executes a new program in the calling process. The exec subroutine does not create a new process, but overlays the current program with a new one, which is called the new-process image. The new-process image file can be one of three file types:
      An executable binary file in XCOFF file format.
      An executable text file that contains a shell procedure (only the execlp and execvp subroutines allow this type of new-process image file).
      A file that names an executable binary file or shell procedure to be run.
    2. execl() system function takes the path of the executable binary file (i.e /bin/ls) as the first and second arguement.then the arguement (i.e -lh, /home) that you want to pass to the executable followed by NULL. Then execl() system function runs the command and prints the output.
    3. The execvp() function is the same with execv() but in its parameter, it gets the file name which is in the PATH environment variable
      1.The execlp() system call duplicates the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character. … The execlp system call can be used when the number of arguements to the new program is known at compile time.
  • Program which forks and executues ls command

    1. [ ]
      Screenshot 2021-11-05 235349

    2. Screenshot 2021-11-05 235501

Source Code Submission

please submit all your codes in a zip file

Session 3 Report

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

  • Read Session Contents.

Section 3.3.1

  • Investigate the /proc/ directory
    1. [FILL HERE with an image of files in /proc/ directories. Use ls command.]

      1

Section 3.3.2

  • 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

  • 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

  • 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

  • 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.

    6

Section 3.3.3

  • Write (in English or Persian) about each file in /proc/(PID) directory:

    • 1. cmdline: if the process has parent and is not a zombie, this file contains the complete command line for the process.
    • 2. environ: when the process was started executing, the initial environment is set. all environment variables are listed in environ. the output is more clear with "strings" command.
    • 3. stat: as its name, it shows the status information of the process. This file shows a lot of num,bers which they have a specific meaning by their order. for example one boolean number says whether this process is running or not. Or so others say if the file is a zombie or stopped or sleeping or etc.
    • 4. status: There are two files: sts and ststm. the status file is a combination of both, in a more human-readle language and format.
    • 5. statm: Shows the status of the process which is related to the memory usage. like shared pages, total memory usage, resident set size, etc.
    • 6. cwd: current working directory. similar to pwd. This is a symbolic link.
    • 7. exe: This file is a symbolic link to the actual pathname of the executed command. If you open it, it opens an executable file.
    • 8. root: We have a per-process root of the filesystem in linux kernel. this file references to the process's root directory. and works line the exe file.
  • 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;
      }

Section 3.3.4

  • Write (in English or Persian) about each file in /proc/ directory:

    • 1. meminfo: information about memory. such as total memory, cached mem, available mem, swap mem, etc.
    • 2. version: As mentioned in task 3.3.2.1
    • 3. uptime: As mentioned in task 3.3.2.2
    • 4. stat: CPU statistical info. how much time each cpu has spent on performing different works. the first line is the sum of all cpu blocks. when the system restarts, all these values start from 0 again.
    • 5. mounts: The 1st column specifies the device that is mounted. The 2nd column reveals the mount point. The 3rd column tells the file-system type. The 4th column tells you if it is mounted read-only (ro) or read-write (rw). The 5th and 6th columns are dummy values designed to match the format used in /etc/mtab.
    • 6. net: This shows various networking parameters and statisticse.g. /dev shows all network devices. /route shows kernet routing table, etc.
    • 7. loadavg: load average to both CPU and IO over time. The first three columns measure CPU and IO utilization of the last one, five, and 15 minute periods. The fourth column shows the number of currently running processes and the total number of processes. The last column displays the last process ID used.
    • 8. interrupts: recording number of interrupts per IRQ. Showing the type of interrupt, device name, num of interrupts per CPU, etc.
    • 9. ioports: a list of currently registered port regions used for io communication with a device.
    • 10. filesystem: a special filesystem which lists all filesystems that arr currently supported by the kernel. It does not exist on a disk.
    • 11. cpuinfo: information about CPU. CPU type, Frequency, num of CPUs that are currently present, cpu cores, cache size, etc.
    • 12. cmdline: Containing commandline of the kernel. showing parameters passed to the kernel at the time it started.
  • 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:

    • dmesg_restrict: This toggle indicates whether unprivileged users are prevented from using dmesg(8) to view messages from the kernel’s log buffer. When dmesg_restrict is set to 0 there are no restrictions. When dmesg_restrict is set to 1, users must have CAP_SYSLOG to use dmesg(8).
    • domainname: These files can be used to set the NIS/YP domainname of your box in exactly the same way as the command domainname.
    • bootloader_type: This gives the bootloader type number as indicated by the bootloader, with a brief encoding for matching kernel header.
    • ngouprs_max: Maximum number of supplementary groups, i.e. the maximum size which setgroups will accept.
    • panic: The value in this file determines the behaviour of the kernel on a panic: if zero, the kernel will loop forever; if negative, the kernel will reboot immediately; if positive, the kernel will reboot after the corresponding number of seconds. When you use the software watchdog, the recommended setting is 60.
    • pid_max: PID allocation wrap value. When the kernel’s next PID value reaches this value, it wraps back to a minimum PID value. PIDs of value pid_max or larger are not allocated.
    • threads_max: This value controls the maximum number of threads that can be created using fork(). minimum is 1, maximum is given by the constant FUTEX_TID_MASK (0x3fffffff)
  • Write your description about /proc/self file

    • [FILL HERE with your description]
      /proc/self is a real symbolic link to the /proc/ subdirectory of the process that is making the call. It is not really a folder, it is a device driver (more accurately, a kernel module) exposing itself as a folder when someone wants to access it. Basically, /proc/self/ represents the process that's reading /proc/self/. So if you try to open /proc/self/ from a C program then it represents that program. If you try to do it from the shell then it is the shell etc..

Source Code Submission

please submit all your codes in a zip file

Session 4 Report

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

  • Read Session Contents.

Section 4.4.1

  • Investigate the ps command
    1. [FILL HERE with an image of ps command showing running processes.]

Screen Shot 1401-08-24 at 11 05 09

  • Information about processes with PID = 1

    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;
}

Section 4.4.2

  • Program using getppid
    1. [ ]
#include <iostream>
#include <unistd.h>
using namespace std;

int main(){
   int pid = fork();
   if (pid == 0) cout << getppid();
   return 0;
}
  1. This is the same process as the process in the first section (systemd).
    The PID of this process is 1. It acts as init system that brings up and maintains userspace service.

Screen Shot 1401-08-24 at 12 18 54

  • Describe the C program (fork program)

    1. The child process pid is 0, thus it returns 23, but the PID of the parent process is not zero, resulting in printing the term "returned code is 23".
  • 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;
}
  • Program printing different messages for parent and child process
#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;
}
  • Program for the last task of this section
    1. [ ]

Screen Shot 1401-08-26 at 14 42 21

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.

Section 4.4.3

  • Program using wait and counting from 1 to 100

    1. Screen Shot 1401-08-26 at 15 12 02
    2. [wait(NULL) will prevent the parent process from continuing until any of its children has completed. If the child process exits before the parent process reaches wait(NULL), it becomes a zombie process until its parent waits on it and it is removed from memory.]
  • Program showing process adoption

    1. [ ]

Screen Shot 1401-08-26 at 15 27 21

1. [ ] 

Screen Shot 1401-08-26 at 15 29 29

Section 4.4.4

  • Describe the following commands/APIs:

    1. execv: The input argument (the path name that identifies the new process image file) should be given as a vector.
    2. execl: name of the program to run will be taken from pathname - the argument will be passed as list.`
    3. execvp: If the input does not contain a directory, this command will look for the name in the PATH environment variable, and the input parameter should be supplied as a vector.
    4. execlp: similar to execvp, however, the input parameter must be supplied as a list
  • Program which forks and executues ls command

    1. [ ]

Screen Shot 1401-08-26 at 16 03 42

1. [ ] 

Screen Shot 1401-08-26 at 16 04 38

Source Code Submission

please submit all your codes in a zip file

  • Zip File HERE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.