c - How to create a process on Mac OS using fork() and exec() -


i working on relatively simple, independent "process starter" work on windows (xp, vista, 7), linux (ubuntu 10.10) , mac os x (10.6). linux , windows work, i'm having trouble mac version. hoping fork() , exec() functions work same way under mac os work in linux. first question is:

  1. should use these create process on mac or there platform specific functions used?

my current code (which worked fine under linux) debug looks this:

pid_t processid = 0; if (processid = fork()) == 0) {     const char * tmpapplication = "/path/to/testapplication";      int argc = 1;     char * argv[argc + 1];      argv[0] = tmpapplication;     argv[1] = null;      execv(tmpapplication, argv); }else {     //[...] } 

any idea if work under mac os x well, because child process not being launched, while there no errors come up.

thank you!

the following program, adapted code, works fine me under os x:

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h>  int main (void) {     pid_t processid;     if ((processid = fork()) == 0) {         char app[] = "/bin/echo";         char * const argv[] = { app, "success", null };         if (execv(app, argv) < 0) {             perror("execv error");         }     } else if (processid < 0) {         perror("fork error");     } else {         return exit_success;     }     return exit_failure; } 

i suggest start simple fragment, , if works keep adding things until find makes break.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -