Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library that has reference to fork() in C

Tags:

c

fork

What is the library that defines fork(). I am learning to use fork(). I found out that the Standard I/O Library : stdio.h is enough for fork() to work but that does not apply in my case.

I am using gcc in Code::Blocks on Windows 8 Pro

My Code is:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>
#include <time.h>

int main(void)
{

    pid_t process;
    process = fork();

    if(process< 0)
    {
        printf("fork failed");
    }
    if(process > 0)
    {
        printf("\nParent Process Executed");
    }

    if(process == 0)
    {
        printf("\nChild Process Executed");
    }
    return 0 ;
}

The Exact Error I get is:

useoffork.o:useoffork.c:(.text+0xf): undefined reference to `fork'

like image 575
cipher Avatar asked Nov 30 '12 10:11

cipher


People also ask

What library is fork () in C?

The C library defines fork() . It is the UNIX/Linux-specific system calls to create a process, on linux etc.

What does fork () do in C?

fork() in C Fork system call is used for creating a new process, which is called child process, which runs concurrently with the process that makes the fork() call (parent process). After a new child process is created, both processes will execute the next instruction following the fork() system call.

What system call does fork use?

The fork() System Call. System call fork() is used to create processes. It takes no arguments and returns a process ID. The purpose of fork() is to create a new process, which becomes the child process of the caller.

Where is fork defined C?

fork() system call is used to create child processes in a C program. fork() is used where parallel processing is required in your application. The fork() system function is defined in the headers sys/types. h and unistd.


2 Answers

The C standard library (glibc) implements fork() which calls a UNIX/Linux-specific system call eventually to create a process, on Windows, you should use the winapi CreateProcess() see this example in MSDN.

Note: Cygwin fork() is just a wrapper around CreateProcess() see How is fork() implemented?

like image 97
iabdalkader Avatar answered Oct 19 '22 22:10

iabdalkader


I am using gcc in Code::Blocks on Windows 8 Pro

You don't have fork on windows. You can use cygwin or something like that though.

like image 23
cnicutar Avatar answered Oct 19 '22 21:10

cnicutar