Information Security system design basics 12th Week study notes

Source: Internet
Author: User

Eighth Chapter Code

EXEC1:



EXECVP () finds the file name in the directory that the PATH environment variable refers to, executes the file after it is found, and then passes the second parameter argv to the file that you want to execute. If the execution succeeds, the function does not return, and the execution fails to return 1 directly, and the reason for the failure is stored in errno. In the result we can see that the EXEVP function call succeeds without returning, so there is no print out "* * * ls is done. Bye ".

EXEC2:



  

The difference between the EXEC1 is that the first parameter of the EXEVP function, EXEC1 is ls,exec2 directly with the arglist[0], but by the definition can be obtained by the two equivalents, the result is the same.

EXEC3:


EXECLP () finds the file name in the directory referred to by the PATH environment variable, executes the file after it is found, and then takes the second later parameter as the file's argv[0], argv[1] ...., the last parameter must be terminated with a null pointer (NULL). If a null pointer is represented by a constant zero, it must be cast to a character pointer, otherwise it will be interpreted as an shaping parameter, and if the length of an integer is different from the length of the char *, then the actual parameters of the EXEC function will be faulted. If the function call succeeds, the process's own execution code becomes the loader's code, and the code behind EXECLP () will not execute. So the running result is the same as EXEC1.

Forkdemo1:


Print the process PID, and then call the fork function to generate the child process, hibernate one second after the process ID is printed again, the parent process prints the child process PID, the child process returns 0.


Forkdemo2:


Two calls fork, which produces four sub-processes, prints four after outputs.

FORKDEMO3:


Fork produces a child process, the parent process returns the child process PID, not 0, so the output of the parent process's sentence, the child process returns 0, so the child process statement is output.

Forkdemo4:


Print the process PID first, then fork to create the child process, the parent process returns the child process PID, so output the parent sentence, hibernate for 10 seconds, the child process returns 0, so the statement after the children output.

FORKGDB:

The parent process prints two sentences, then sleeps for a second, then prints a sentence, the child process first prints a sentence, then sleeps for a second, and then prints two sentences. And these two threads are concurrent, so you can see that one thread sleeps in the second, another thread is executing, and the threads are independent of each other.

PSH1:


Enter the instruction to execute, enter to indicate the end of the input, and then enter each parameter corresponding to the function, and then call the corresponding instruction.

PSH2:


More circular judgment, do not exit the words will always want you to enter the instruction, and for the existence of the sub-program state conditions.

TESTBUF1:

Line break output
TESTBUF2:

Ditto, the code is ' \ n '.

TESTBUF3:

  no newline output. The content is formatted to output to the standard error, the output stream.

 

Testpid:


Outputs the PID of the current process PID and the parent process of the current process.

TESTPP:


I don't know why.

Testsystem:


Executes the shell command, which is to send an instruction to DOS. Here is the following can be followed by two parameters, and then sent to DOS these two commands, executed separately. Enter the LS and dir two instructions and execute them separately.

Waitdemo1:


If there are child processes, the child process is terminated and the child process PID is successfully returned.

Waitdemo2:

Compared to the previous program, there is a sub-process of state separation, split the state into three pieces, Exit,sig and core.

Reference: Http://www.cnblogs.com/20135202yjx/p/5003653.htmlproblems encountered:

In the beginning, there are compiled files in the folder, thinking of running directly, resulting in insufficient permissions. Finally, compile and run the result directly, verify the code.

Innocent "segment error (Core dump)" error in TESTPP.

Information Security system design basics 12th Week study notes

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.