License Public Domain
Lines 25
Keywords
exec (1) fork (1) POSIX (2) process launch (4)
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Siafoo is here to make coding less frustrating and to save you time. Join Siafoo Now or Learn More

Launching a sub process using the POSIX API Atom Feed 0

In Brief An example of sub process launching under a POSIX compliant OS like Linux, Unix, (OS X should work too).
# 's
 1#include <errno.h>
2#include <stdio.h>
3#include <sys/types.h>
4#include <unistd.h>
5
6int main(int argc, char **argv)
7{
8 int pid;
9 int status;
10
11 switch(pid = fork())
12 {
13 case -1: // ERROR!
14 printf("Error with code %i\n", errno);
15 return errno;
16 case 0: // Child
17 printf("Child Running\n");
18 status = execv("/bin/date", 0);
19 break;
20
21 default:
22 wait(0);
23 // Process the results from the child
24 printf("Parent Exiting\n");
25 break;
26 }
27
28 return 0;
29}

An example of sub process launching under a POSIX compliant OS like Linux, Unix, (OS X should work too).