Brian Lee
Brian Lee

Reputation: 107

How to execvp with two main functions in C?

I am trying to use execvp in my code but I am having trouble. For example purposes, let's say I have two .c files called 1.c and 2.c. In 1.c I need to fork() to make a parent and child class process, all included in main(). In 2.c is a function to countdown from 5 to 1, all included in main() as well. My question is, how do I use execvp from 1.c to execute 2.c in the parent? Whenever I try to compile, it keeps giving me an error saying redeclaration of main.

Upvotes: 0

Views: 92

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 753900

You use execvp() to execute a new program. By the sounds of it, you need to compile 1.c to make program 1, and you need to compile 2.c to create program 2, and you need program 1 to fork() and the child to execvp() program 2. They are, however, separate executables, each with its own main().

Upvotes: 4

Related Questions