/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Development/languages/C/Samples/fork/fork.c

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <sys/types.h>
 
3
#include <sys/stat.h>
 
4
#include <unistd.h>
 
5
 
 
6
extern int errno;
 
7
 
 
8
void runparent(pid_t child) {
 
9
        // Waiting for child to be finished!
 
10
        waitpid(child,NULL,0);
 
11
 
 
12
}
 
13
 
 
14
void runchild() {
 
15
        execl("/bin/bash","bash","-c","ls -la > hell.txt");
 
16
        printf("%i",errno);
 
17
}
 
18
 
 
19
main() {
 
20
        pid_t child;
 
21
        
 
22
        child=fork();
 
23
        if (child>0) runparent(child);
 
24
        else if (child==0) runchild();
 
25
        else printf("Error forking child, error: %i!\n",errno);
 
26
}