20145326 Cai "Information Security system design basics" 12th Week study Summary

Source: Internet
Author: User
Tags signal handler

20145326 Cai "The basis of information security system design" 12th Week study summary of learning Contents
    • Summary of the Nineth Week learning content

    • Summary of the tenth week learning content

    • Summary of the 11th Week learning content

Video learning and practice pointers and statements

The declaration of a variable in the C language consists of two parts:

    • Type

    • Declarator

For a simple type, the declaration does not have much of a reading barrier to the code, and for the identification of complex types it can be judged by right-left-hand method.

Pointer array, array pointer, pointer function, function pointer difference array pointer (also called row pointer)

define INT (*p) [n];

    • () high priority, the first explanation is that p is a pointer to an integer one-dimensional array, the length of the one-dimensional array is n, it can be said that the step of P. In other words, when executing p+1, p crosses the length of n integer data.

    • To assign a two-dimensional array to a pointer, you should assign this value:

      int a[3][4];
      int (*p) [4]; The statement defines an array pointer to a one-dimensional array with 4 elements.

      p=a;//assigns the first address of the two-dimensional array to p, i.e. a[0] or &a[0][0]
      p++; After the statement executes, that is, P=p+1;p crosses line a[0][] points to the line a[1][]

So an array pointer is also called a pointer to a one-dimensional array, also known as a row pointer. Array of pointers

define int *p[n];

    • [] High priority, the first combination with P as an array, and then by int* that this is an integer pointer array, it has n pointer type array elements. When P+1 is executed, p points to the next array element, so that the assignment is wrong: P=a, because P is an unknown representation, only p[0], p[1], p[2]...p[n-1], and they are pointer variables that can be used to hold variable addresses. But can be so p=a; Here p represents the value of the first element of the pointer array, the value of the first address of a.
    • To assign a two-dimensional array to a pointer array:
      int *p[3];
      int a[3][4];
      p++; The statement indicates that the P array points to the next array element. Note: Each element of this array is a pointer
      for (i=0;i<3;i++)
      P[i]=a[i]

Here int *p[3] indicates that a one-dimensional array holds three pointer variables, respectively p[0], p[1], p[2] so assign values separately.

    • So the difference between the two is enlightened, the array pointer is just a pointer variable, it seems that the C language is specifically used to point to a two-dimensional array, it occupies memory of a pointer to the storage space. Pointer arrays are multiple pointer variables that exist in the form of an array of memory, occupying multiple pointers of storage space.
    • It is also important to note that both the reference and the array name reference are the same when used to point to a two-dimensional array.

    • For example, to represent an array of I row J columns an element: (P[I]+J), (* (p+i) +j), ((P+i)) [j], P[i][j], Priority: () >[]>

function pointers
    • In the C language, a function always occupies a contiguous memory area, and the function name is the first address of the memory area that the function occupies. We can assign this first address of the function (or the entry address) to a pointer variable, Make the pointer variable point to the function. The function can then be found and invoked by a pointer variable. We refer to this pointer variable to the function as a function pointer variable.

    • The general form of a function pointer variable definition is:

Type descriptor (* pointer variable name) ();

    • Where the type specifier represents the type of the returned value of the referred function. (* pointer variable name) "means that the variable following the" "is a pointer variable defined. The last empty parenthesis indicates that the pointer variable refers to a function.
      For example: Int (PF) ();
      Indicates that PF is a pointer variable to the function's entry, and the return value of the function is an integer type.
Pointer functions
    • A function type is the type of the return value of a function. The return value of a function that is allowed in C is a pointer (that is, an address), and the function that returns a pointer value is called a pointer-type function.
    • The general form of defining a pointer-type function is:
      Type specifier function name (formal parameter list)
      {
      .../function Body */
      }
    • Where the function name is preceded by the "" number indicates that this is a pointer-type function, that is, the return value is a pointer. The type specifier represents the data type that the returned pointer value points to.
      Such as:
      int ap (int x,int y) {
      ./function Body/
      }
      Indicates that the AP is a pointer-type function that returns a pointer value, and the pointer that it returns points to an integer variable.
Right and left method
    • Specific methods:

1. Starting with the variable name, right and left, alternately looking outward, write on the paper: "Variable is"

2. If you encounter the left parenthesis to the right, write down on the paper: "Function, parameter is" and use the same method to handle each parameter in parentheses--write on the paper: "Back"

3. If you encounter square brackets to the right, write on the paper: "Array, length {square brackets}, Element type"

4. If right side parenthesis is encountered, do nothing

5. If you encounter * on the left, write on the paper: "Pointer, point to"

6. If any type is encountered on the left, write down the corresponding type name on the paper

The generation of signals
    • Generated by the user, such as: CTRL + C generates SIGINT signals, etc., can be stty-a to see which keys can generate signals
    • Generated by hardware, such as: the current process executed the instruction divided by 0
    • Sent by a process, such as: You can send a signal to a specified process using the command kill-signal designator PID under the shell process.
    • Generated by the kernel, such as: Alarm clock timeout generates SIGALRM signal.
Three ways to handle the signal:
    • Ignore
    • Default handling: Default handling by operating system settings
    • Custom signal Processing: customizable signal processing functions
Capturing signals
    • man -k signalto retrieve related functions using commands:

    • The sigdemo1.c run results as shown:

    • Analysis: Each time the signal function sets the specific signal processing function (non-sig_ign) to take effect only once, each time the process responds to processing signals, the signal processing function reverts to the default processing mode
Ignore signal
    • The sigdemo2.c run results as shown:

    • To view the SIG_IGN macro variable:

    • As the figure shows, Sig_ign is a handler that ignores the signal, represents a function pointer with no return value, and a pointer value of 1.
Default signal
    • To view the SIG_DFL macro variable:

    • The graph shows that SIG_DFL is the handler for the default signal, which represents a function pointer with no return value, with a pointer value of 0

    • The SIGDEMO2.C code looks like this:

    • If you change the sigign to SIGDFL, the result of the operation becomes as follows

    • Analysis: SIG_IGN is to ignore the signal, that is, when the keyboard input an Ctrl+C interrupt instruction, the program will ignore it, and changed SIG_DFL to revert to the default state, after entering the interrupt instruction, the natural program will be interrupted.
The difference between signal and sigaction

Signal's question:

    • I don't know why the signal was sent.

    • Unable to safely block other signals during signal processing

Sigaction's question:

    • When the signal handler is called, the new signal screen word created by the system automatically includes the signal being delivered. This ensures that when a given signal is processed, if the signal occurs again, it will be blocked until the end of the processing of the previous signal.

    • After the response function is set, it is valid and does not reset

function of the sleep () function with signal implementation

The implementation of sleep () should be divided into three steps:

    • Register a signal signal (sigalrm,handler).
    • Call the alarm () function.
    • Pause () suspends the process.
Experience

This week I studied the video content and reviewed the code for 第九、十、十 week. I found a lot of things although learned, but after a while will forget, so review is very necessary! Before due to the weekly learning tasks are relatively heavy, so some code does not have a more detailed understanding of the analysis, this week just can be taken to review the consolidation of what has been learned before, is so-called "warm know new, can for the teacher", through the continuous review, the foundation will be more solid!

Learning progress Bar
Lines of code (new/cumulative) Blog volume (Add/accumulate) Learning time (new/cumulative) Important growth
Goal 5000 rows 30 Articles 400 hours
First week 0/0 1/2 20/20
Second week 58/58 1/3 20/40
Third week 150/208 1/4 22/62
Week Five 150/358 1/5 21/83
Week Six 136/494 1/6 25/108
Seventh Week 115/609 2/8 24/132
Eighth Week 0/609 2/10 22/154
Nineth Week 109/718 3/13 20/174
Tenth Week 472/1190 1/14 21/195
11th Week 1883/3073 3/17 21/216
12th Week 0/3073 2/19 20/236

20145326 Cai "Information Security system design basics" 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.