0

I'm trying to create a child process using Clion 2016.1 but its failing

I included the header file unistd.h but this is not useful

here is my source code:

#include <stdio.h>

#include <sys/types.h>
#include <unistd.h>


int main(int argc, char **argv)
{
    printf("--beginning of program\n");

    int counter = 0;
    pid_t pid = fork();

    if (pid == 0)
    {
        // child process
        int i = 0;
        for (; i < 5; ++i)
        {
            printf("child process: counter=%d\n", ++counter);
        }
    }
    else if (pid > 0)
    {
        // parent process
        int j = 0;
        for (; j < 5; ++j)
        {
            printf("parent process: counter=%d\n", ++counter);
        }
    }
    else
    {
        // fork failed
        printf("fork() failed!\n");
        return 1;
    }

    printf("--end of program--\n");

    return 0;
} 

here is my and error message:

toolchains setting

error message

linuxD
  • 27
  • 2
  • 12

0 Answers0