Clone creation of linux processes and threads

Source: Internet
Author: User
Linux process and thread clone create Java code www.2cto.com [B] Linux process and thread creation are achieved through clone. the clone function is powerful and has many parameters. clone allows you to selectively inherit the resources of the parent process. you can choose the same as vfork...
Linux process and thread clone create Java code www.2cto.com [B] Linux process and thread creation are achieved through clone. the clone function is powerful and has many parameters. clone allows you to selectively inherit the resources of the parent process. you can share a virtual storage space with the parent process like vfork, this creates a thread, and you can not share it with the parent process. you can even choose to create a parent-child relationship between the process and the parent process, instead, the sibling relationship [/B] pthread_create is implemented based on clone and is actually created by processes, but these processes share many things with the parent process, shared things do not need to be copied to sub-processes, thus saving a lot of overhead. Therefore, these sub-processes are also called light-weight processes (light-weight process) in linux after the thread is a lightweight process fork, what can be copied by a sub-process is summarized in one sentence, that is, all writeable data will be copied. including: Heap, stack, data segment, not beginning START data segment, open file descriptor, handler installed on the signal, shared library, ipc (shared memory, message queue, semaphore). Note that the pending signal will not be inherited, the new process resets its pending signal chain. the sub-process and the parent process share something in one sentence, that is, all read-only things do not need to be copied, and the parent and child processes share, including: what are the body segments and string constants? the child process will not inherit the process id from the parent process, various locks (memory locks, file locks), timers, and pending signals in the operating system. If a user-level thread corresponds to a system-level thread, the linux multi-core features can be fully utilized. However, in earlier linux versions, multiple threads of linux user-level processes correspond to one system-level process and cannot fully utilize the features of the operating system!
Related Article

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.