Some basic knowledge of process related to file copy of multi-process under Linux

Source: Internet
Author: User
Tags file copy

Before the implementation of the file IO to achieve a copy of the file, then for the process, we can also implement it?

The answer is yes.

Process resources:

first, let's review what resources are needed to run the process.   Its resources include CPU resources, memory resources, and of course , time slice resources, we all know that the process is stack, heap, read-only data segment, data segment (initialized global variable static variable),BSS segment (uninitialized), The code snippet also has a set of register values.

Process command:

We can also view the process number (PID) and parent process number (PPID) through the ps-ef |grep process name command, and then through

PS aux |grep process name or process number to see the status of the process (r,t,s,z, (+) ... ). By the kill-signal sequence number or the macro-PID signal to send various signals, note that the kill is not the meaning of killing process, we can send a signal to the process to kill the process Kill-sigkill PID, of course, we can pass Kill-l to get the name of the macro, and then we use nice or renice to set different priorities for our process, and so on.

Process creation:

We'll use the fork function to create the process, which we've all cleared up until a function can return only one return value, then the process does the created function return only one? The answer is wrong, because the process created by the fork function, if successful we return the PID number of the child process to the parent process, return 0 to the child process, and return 1 to the parent process if the creation fails. After the child process is created, the parent process starts execution from the next statement in Fork (), and the child process executes from the next statement?

Yes, because the PC register value of the parent process is copied when the child process is created, and the value of the PC register determines where your process is , so when the child process is created, our child processes are executed in the same way as the parent process, but note that the two is not a piece of, there are relations, but the relationship is not sure, if you use the Vfork function to create a process, then our child process is the first.

So what's the difference between the fork () function and the vfork () function that can create a process?

<1>fork when a child process is created, the order in which the parent-child process executes is indeterminate and the address space of the parent-child process is independent.

<2>vfork after the child process is created, the Wahabbi is guaranteed to execute first, the parent process ends, or the EXEC function family is called before execution begins.

and the parent-child process shares the same address space "if the child process calls the EXEC function, the child process will be independent".

So how do you use the process to copy files? And how to copy it? The requirements of the implementation of the following, the parent process copies the first half of the file copy files , then the efficiency above we certainly higher than a process, the above is the relevant review of the process knowledge, knowledge points have, ideas have, So the rest is just a matter of code implementation, that is, manual labor:

Take a look at the implementation of the following code:


#include 

Note:

This program used in the header file I directly encapsulated in the head.h. If there's any need for improvement, I want a message.



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.