开发者

Fork Programming in C at Linux Environment

开发者 https://www.devze.com 2023-03-16 06:16 出处:网络
Can anyone help me to know the fork process in c Programming and how it\'s working on the real time application.And sample pro开发者_Go百科gram for that.#include <stdio.h>

Can anyone help me to know the fork process in c Programming and how it's working on the real time application.And sample pro开发者_Go百科gram for that.


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

int main()
{
    pid_t pid;
    pid = fork();

    if(pid == 0){
        printf("child process\n");
    }
    else{
        printf("parent process\n");
    }
    return 0;
}


The complete reference of the C libraries is already on your PC, if it has Linux on it, at least. You can find almost every system call / supported C function via the man pages. Try typing man fork at the console and see what magic happens. :) You can search in the man pages by pressing the / key then type your string and press enter after that you can search for the next occurrence by pressing n. Good luck!


Wikipedia states

Fork-exec is a commonly used technique in Unix whereby an executing process
spawns a new program

Related SO question : Applications of fork system call

Sample code: http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html

0

精彩评论

暂无评论...
验证码 换一张
取 消