20135210 Ellis--The basic design of information security system 12th Week study summary

Source: Internet
Author: User

EXEC1.C: The program call Execvp:arglist is a string array of command lines, the first element of the array is the program name, and the last element must be null.



Second, exec2.: The difference between EXEC2 and EXEC1 is: EXECVP (arglist[0], arglist), but these two are equivalent, so the result is not different.

The EXECLP () function belongs to the EXEC () function family, which is the front end of the EXECVE (2) function.

EXECLP finds the file from the PATH environment variable and executes it. 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

Third, Forkdemo1: First print the process PID, and then call the fork function to generate a child process, hibernate one second after the process ID printing, the parent process to print the child process PID, the child process returned 0.

Four, Forkdemo2: This code calls two times fork, altogether produces four sub-processes, prints out four aftre outputs.

V. Forkdemo3:fork produces a child process, the parent process returns the child process PID, not 0, so the output of the parent process of the sentence, the child process returns 0, so the child process will output the sentence.

Six, Forkdemo4: First print the process PID, and then fork to create a child process, the parent process returns the child process PID, so output the parent sentence, sleep 10 seconds, the child process returned 0, so the output of the children and the following sentence.

Seven, Forkgdb

The parent process prints two sentences, then sleeps for a second, and then prints a sentence. The child process prints a sentence, then sleeps for one second, then prints two sentences. These two threads are concurrent, so you can see that one thread sleeps in the second and another thread executes.



Eight:testbuf1: This code is used to output Hello, enter does not exit.

#include <stdio.h>
#include <stdlib.h>
int main ()
{
printf ("Hello");
Fflush (stdout);
while (1);
}

Testbuf2 : The effect is the same. Conclusion: Fflush (stdout) and newline characters \ n have the same effect.

#include <stdio.h>
int main ()
{
printf ("hello\n");
while (1);
}

testbuf3 : The content is formatted to output to the standard error, the output stream.

#include <stdio.h>

int main ()
{
fprintf (stdout, "1234", 5);
fprintf (stderr, "ABCD", 4);
}

Testpid : outputs the PID of the current process PID and the parent process of the current process.

#include <stdio.h>
#include <unistd.h>

#include <sys/types.h>

int main ()
{
printf ("My PID:%d \ n", Getpid ());
printf ("My parent ' s PID:%d \ n", Getppid ());
return 0;
}

IX: Testsystem: Outputs the result of two instructions at the same time.

Ten: FIFO folder

FIFO strictly follow first-out, the pipeline and FIFO read always return data from the beginning, the writing of their data to add to the end. They do not support file location operations such as Lseek ().

Each program has an environment table, which is an array of character pointers, where each pointer contains an address of a null-terminated C string. The global variable environ contains the address of the array of pointers.

Xi. Pipe Folder

Call pipe to create a pipe and connect both ends to two file descriptors, Array[0] is the file descriptor of the read data side, and Array[1] is the file descriptor of the write data side, internal is hidden in the kernel, the process can only see two file descriptors.

Resources

Teaching Material: Eighth chapter, detailed study instruction: http://group.cnblogs.com/topic/73069.html

Shang Classmate's Blog: http://www.cnblogs.com/20135202yjx/p/5003653.html

20135210 Ellis--The basic design of information security system 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.