Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Creating a process in C

julien@ubuntu:~/c/shell$ cat fork.c
#include <stdio.h>
#include <unistd.h>

/**
 * main - fork example
 *
 * Return: Always 0.
 */
int main(void)
{
    pid_t my_pid;
    pid_t pid;

    printf("Before fork
");
    pid = fork();
    if (pid == -1)
    {
        perror("Error:");
        return (1);
    }
    printf("After fork
");
    my_pid = getpid();
    printf("My pid is %u
", my_pid);
    return (0);
}
julien@ubuntu:~/c/shell$ ./fork 
Before fork
After fork
My pid is 4819
julien@ubuntu:~/c/shell$ After fork
My pid is 4820
Source by alx-intranet.hbtn.io #
 
PREVIOUS NEXT
Tagged: #Creating #process #C
ADD COMMENT
Topic
Name
7+7 =