reverie/tests/c_tests/forkExec.c
Vladimir Makaev 03cbd6044d update hermetic_infra/** files with correct license header - 1/x
Summary:
Followed guide here https://www.internalfb.com/intern/wiki/Linting/License_Lint/ to add fbcode/hermetic_infra/** code to license linter. As we have parts of our code shipped as Open Source it's important to get this automated

This diff is updating existing file's licenses to not get conflict after lint rule enablement

Reviewed By: jasonwhite

Differential Revision: D40674080

fbshipit-source-id: da6ecac036f8964619cf7912058f3a911558e7b1
2022-10-26 12:18:14 -07:00

44 lines
1 KiB
C

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char* argv[], char* envp[]) {
if (argc == 2 && strcmp(argv[1], "child") == 0) {
printf("exec pid: %u\n", getpid());
_exit(0);
}
pid_t pid = fork();
if (pid < 0) {
perror("fork failed: ");
exit(1);
} else if (pid == 0) {
char* prog = argv[0];
char* const newArgv[] = {prog, "child", NULL};
printf("child pid: %u\n", getpid());
execve(prog, newArgv, envp);
printf("exec failed: %s\n", strerror(errno));
} else {
int status;
printf("parent pid: %u\n", getpid());
waitpid(pid, &status, 0);
if (WIFSIGNALED(status)) {
printf("%u terminated by signal: %u\n", pid, WTERMSIG(status));
}
}
}