C Language Development in Linux (Process Creation)

Source: Internet
Author: User

[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]

In Linux, creating a process is very interesting. As we all know, processes are the basic unit for enjoying Resources in the operating system. In Linux, how should we create a process? In fact, it is very simple, and a fork function can be done. However, we need to know that, apart fromCodeIs shared, stack data and global data are independent.

# Include <unistd. h> # include <stdio. h> # include <stdlib. h> # include <math. h> # include <errno. h> # include <sys/types. h> # include <sys/Wait. h> int main () {pid_t PID; If (-1 = (pid = fork () {printf ("error happened in fork function! \ N "); Return 0;} If (0 = PID) {printf (" this is child process: % d \ n ", getpid ());} else {printf ("this is parent process: % d \ n", getpid ();} return 0 ;}

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.