fork() creates a child process that is a copy of the parent (copy-on-write makes this cheap); it returns 0 in the child, the child's PID in the parent, and -1 on failure.
exec() replaces the calling process's memory image with a new program; the PID stays the same and the call does not return on success.
The classic shell pattern is fork, then exec in the child to run a command, while the parent calls wait() to collect the exit status.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void) {
pid_t pid = fork();
if (pid < 0) { perror("fork"); exit(1); }
if (pid == 0) { // child
execlp("ls", "ls", "-l", NULL); // replaces the child's image
perror("exec failed");
_exit(1);
} else { // parent
int status;
waitpid(pid, &status, 0); // reap the child
printf("child exited with %d\n", WEXITSTATUS(status));
}
return 0;
}