How to spawn another process in C

1 Answer

0 votes
#include <unistd.h>
#include <stdio.h>

int main()
{
    int mypid = fork(); // fork() creates a clone of the process 

    if (mypid == 0) {
        printf("child process - %d\n", getpid());
    }
    else {
        printf("parent process - %d\n", getpid());
    }

    return 0;
}




/*
run:

parent process - 22
child process - 23

*/

 



answered Jun 12, 2023 by avibootz
edited Jun 12, 2023 by avibootz

Related questions

1 answer 184 views
184 views asked May 1, 2021 by avibootz
1 answer 187 views
1 answer 262 views
2 answers 246 views
1 answer 248 views
248 views asked Jun 30, 2019 by avibootz
...