1

Can anyone help me to know the fork process in c Programming and how it's working on the real time application.And sample program for that.

simbu94
  • 1,012
  • 2
  • 10
  • 22
  • 2
    What have you figured out so far? – Dhaivat Pandya Jun 29 '11 at 06:08
  • 2
    I'm sorry, I can't quite tell what you're meaning to ask. Are you asking for an example of how to use `fork()` in C? If you are, there's an example on the [Wikipedia article](http://en.wikipedia.org/wiki/Fork_(operating_system)) for `fork()`. – Jordan Wade Jun 29 '11 at 06:08
  • possible duplicate of [fork() execution process](http://stackoverflow.com/questions/5010359/fork-execution-process) – Fred Foo Jun 29 '11 at 06:26

3 Answers3

3
#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;
}
EsmaeelE
  • 2,331
  • 6
  • 22
  • 31
1

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!

Samveen
  • 3,482
  • 35
  • 52
DipSwitch
  • 5,470
  • 2
  • 20
  • 24
0

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

Community
  • 1
  • 1
Praveen S
  • 10,355
  • 2
  • 43
  • 69