Information Security System Design Foundation 12th Week study Summary

Source: Internet
Author: User

Chapter1 Video Learning Notes

PS. This part because I am watching the video with paper notes, do not want to write in the blog = =. But I think it should be put up for review. For the time being put up with photos, and so on after the code is finished and then organized into text.

Chapter2 Process Control part of the video Code Practice 1.GET_PID.C operation (1) GCC compilation trial:

The GET_PID.C code is as follows:

The code differs from the code in the video, and at first the compilation fails, and I modify it:

①printf Statement missing precompiled Directive # include <STDIO.H>, which is missing from the code in the video. The GCC compilation needs function in ②mac contains the return value description, that is, the main function cannot have an int. So I changed the main function. This is what the code in the video does not have.

The last compile passes, and prints out the ID number of the currently executing process: 7234.

Conclusion: This function is used to print the ID number of the current execution process.

(2) Continuous operation GE_PID.C output process number:

Here, the process number running two times in the video is only 1, and my output is different from 16 and 6.

I guess because there are too many programs running in the background in my system = =.

Conclusion: The process numbers that run the same program output at different times are different because this is a different process.

Operation of the 2.FORK_TEST.C

(1) Implementation of GCC compilation

(2) The code of FORK_TEST.C is as follows:

This code also has a compilation problem in practice:

Exit (1) need to have precompiled Directive # # <STDLIB.H>, otherwise the compilation will not pass, this is not in the video code.

After the code runs, the ID number of the parent-child process is printed successfully. The count value accesses than either is 1 and accesses than either is 0.

Conclusion: The order of execution of parent-child processes is determined by different operating systems. is variable.

Operation of the 3.VFORK_TEST1.C

(1) GCC compilation trial:

(2) The code of VFORK_TEST1.C is as follows:

This code is intended to reflect that the child process created by the Vfork function is a shared data segment with the parent process, so the output count is the value after the child process's count value plus one after the child process executes and then the parent process, which is 2.

Conclusion: This code is used to illustrate that the child process created by the Vfork function is a shared data segment with the parent process.

Operation of the 4.VFORK_TEST2.C

(1) GCC compilation trial:

(2) The code of VFORK_TEST2.C is as follows:

Conclusion: When a child process is created with Vfork, the parent process is suspended during the execution of the child process.

<<<< add: I try to modify the code

Modify the following (add count++ before the child process executes part of the For Loop if end):

The output is:

The count value becomes 2. Once again , the characteristics of the child process and the parent process having shared data segments are described.

Chapter3 Process Code Package Practice 1.FORKDEMO1.C operation

The code is as follows:

#include <stdio.h> #include   <sys/types.h> #include   <unistd.h>int main () {int ret_from_fork , Mypid;mypid = Getpid ();   printf ("Before:my pid is%d\n", mypid); ret_from_fork = fork (); Sleep (1);p rintf ("After:my pid is%d, fork () said%d\n", get PID (), ret_from_fork); return 0;}
Operation of the 2.FORKDEMO2.C

The code is as follows:

#include <stdio.h> #include <unistd.h>int main () {printf ("Before:my pid is%d\n", getpid ()); fork (); fork (); printf ("Aftre:my pid is%d\n", getpid ()); return 0;}
Operation of the 3.FORKDEMO3.C

The code is as follows:

#include <stdio.h> #include   <stdlib.h> #include   <unistd.h>int main () {intfork_rv;printf (" Before:my pid is%d\n ", getpid ()); fork_rv = fork ();/* Create new process*/if (FORK_RV =-1)/* Check for Error*/perror ( "fork"), else if (FORK_RV = = 0)        {printf ("I am the child.  My pid=%d\n ", Getpid ()); exit (0);} else        {printf ("I am the parent. My child is%d\n ", FORK_RV); exit (0);} return 0;}    
Operation of the 4.FORKDEMO4.C

The code is as follows:

#include <stdio.h> #include   <stdlib.h> #include   <unistd.h>int main () {intfork_rv;printf (" Before:my pid is%d\n ", getpid ()); fork_rv = fork ();/* Create new process*/if (FORK_RV =-1)/* Check for Error*/perror ( "fork"), else if (FORK_RV = = 0)        {printf ("I am the child.  My pid=%d\n ", Getpid ());p rintf (" Parent pid=%d, my pid=%d\n ", Getppid (), Getpid ()); exit (0);} else        {printf ("I am the parent. My child is%d\n ", FORK_RV); sleep (); exit (0);} return 0;}
Operation of the 5.FORKGDB.C

The code is as follows:

#include <stdio.h> #include <stdlib.h> #include <unistd.h>int  gi=0;int main () {int li=0;static int si=0;int i=0;pid_t pid = fork (), if (PID = =-1)        {exit (-1);} else if (PID = = 0)        {for (i=0; i<5; i++)                {printf (' Child li:%d\n ', li++); sleep (1);p rintf ("Child gi:%d\n", gi++); printf ("Child si:%d\n", si++);} Exit (0);} else        {for (i=0; i<5; i++)                
Operation of the 6.PSH1.C

The code is as follows:

#include <stdio.h> #include <stdlib.h> #include <string.h> #include    <unistd.h># Definemaxargs20#definearglen100int execute (char *arglist[]) {EXECVP (arglist[0], arglist);p error ("EXECVP failed"); Exit (1);} char * makestring (char *buf) {Char*cp;buf[strlen (BUF)-1] = ' + '; cp = malloc (strlen (BUF) +1); if (cp = = NULL) {fprintf (St Derr, "no memory\n"); exit (1);} strcpy (CP, BUF); return CP;} int main () {Char*arglist[maxargs+1];intnumargs;charargbuf[arglen];numargs = 0;while (Numargs < MAXARGS) {printf (" ARG[%D]? ", Numargs); if (Fgets (Argbuf, Arglen, stdin) && *argbuf! = ' \ n ') arglist[numargs++] = makestring (ARGBUF); else{if (Numargs > 0) {Arglist[numargs]=null;execute (arglist); Numargs = 0;}}} return 0;}
Operation of the 7.PSH2.C

The code is as follows:

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <signal.h> #defineMAXARGS20 #definearglen100char * Makestring (char *buf) {Char*cp;buf[strlen (BUF)-1] = ' strlen ', CP = malloc (BUF (fprintf) +1), if (cp = = NULL), (stderr, "n o memory\n "); exit (1);} strcpy (CP, BUF); return CP;} void execute (char *arglist[]) {intpid,exitstatus;pid = fork (); switch (PID) {case-1:perror ("fork failed"); exit (1); case 0 : EXECVP (arglist[0], arglist);p error ("EXECVP failed"), exit (1);d efault:while (Wait (&exitstatus)! = pid);p rintf (" Child exited with status%d,%d\n ", Exitstatus>>8, exitstatus&0377);}} int main () {Char*arglist[maxargs+1];intnumargs;charargbuf[arglen];numargs = 0;while (Numargs < MAXARGS) {printf (" ARG[%D]? ", Numargs); if (Fgets (Argbuf, Arglen, stdin) && *argbuf! = ' \ n ') arglist[numargs++] = makestring (ARGBUF); else{if (Numargs > 0) {Arglist[numargs]=nuLl;execute (arglist); Numargs = 0;}}} return 0;}
Operation of the 8.EXEC1.C

The code is as follows:

#include <stdio.h> #include <unistd.h>int main () {char*arglist[3];arglist[0] = "ls"; arglist[1] = "-L"; ARGLIST[2] = 0;//nullprintf ("* * * ~ to exec ls-l\n"); EXECVP ("ls", arglist);p rintf ("* * * * ls was done. Bye "); return 0;}

Because there is a lot of content in the code package. Don't show them all. The general process is that GCC is compiled and run. Specific features and code implications need to be understood in depth. I think the focus is on a few examples of the fork function and an example of the Exec family function. The meaning of the code is duplicated in the video. The emphasis is on understanding the order of execution of child and parent processes.

Problems encountered by Chapter4 and their solutions

The main problem is the understanding of the code. I think there is a lot to see. The solution should be a lot of running more experience it. It looks like there's no other way.

There is the problem in the video, there is a I asked in the group, waiting for a reply. Other questions I have mentioned in the Chapter3 code operation above. Modification of the solution is also noted, and then all transferred.

I'm still working on it!

Chapter5 Learning Experience

This week's task is to learn the code (the code in the process compression package). I first followed a few days of teaching video, I intend to learn the process control, process communication content, learn a solid point, because I read the book last week to learn self-feeling bad, read a lot of confusion, code execution is also less. This week's code package gives me a good chance to practice understanding! So I just took the code out of the video in handy. The feeling learned a lot of content. In particular, the function of fork such functions are in the execution of the code to feel its principle. It was really touching when I finished it!!!

Because there is also a recent project of this course, the internet also searched a lot of communication between the process of information, it is simply this part of the knowledge throughout the daily learning. Every day of learning is the pipeline, fork, signal volume and so on. I hope that at the same time a lot of sentiment, the material can make up for some cognitive loopholes.

There is a lot of code in the process package. And many really do not understand, think there is a long way to go = =. Blog after the hand or to continue to step up ... Keep looking.

Information Security System Design Foundation 12th Week study Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.