How to launch new process on mac

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <unistd.h>

int main()
{
        pid_t pid;
        pid = fork();
        if(pid > 0 )
        {
                printf("Parent process!\n");
        }
        else
        {
                printf("Child process\n");
                int i =       execl("/Applications/TextEdit.app","/Applications/TextEdit.app", (char*)0);
                printf("\n%d\n", i);
        }

        return 0;
}

I am trying a open TextEdit application using this code. I am not getting why this is not working.

Last edited on
I don't know Macs, but is .app the extension for executables on the Mac OS? What is execl returning? What is errno?
execl giving error code 1
Suppose I have to open firefox, crome or any other application ( except command line ) in linux then in that case what I have to pass in execl() function.
man wrote:
int execl(const char *path, const char *arg, ...);
execl( "/usr/bin/firefox", "/usr/bin/firefox", (char *) NULL ); The first argument is the executable, then it comes arg0 (that by convention points to the file to be executed), arg1, ..., and ends with a NULL pointer.

execl giving error code 1
man wrote:
If any of the exec() functions returns, an error will have occurred.
The return value is -1, and errno will be set to indicate the error.
Check errno, (use perror if you want)
Topic archived. No new replies allowed.