<commit_before>/*  Author:     Makarius

Bash process group invocation.
*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>


static void fail(const char *msg)
{
  fprintf(stderr, "%s\n", msg);
  exit(2);
}


int main(int argc, char *argv[])
{
  /* args */

  if (argc != 3) {
    fprintf(stderr, "Bad arguments\n");
    exit(1);
  }
  char *pid_name = argv[1];
  char *script = argv[2];


  /* report pid */

  FILE *pid_file;
  pid_file = fopen(pid_name, "w");
  if (pid_file == NULL) fail("Cannot open pid file");
  fprintf(pid_file, "%d", getpid());
  fclose(pid_file);


  /* setsid */

  if (setsid() == -1) {
    pid_t pid = fork();
    if (pid == -1) fail("Cannot set session id (failed to fork)");
    else if (pid != 0) exit(0);
    else if (setsid() == -1) fail("Cannot set session id (after fork)");
  }


  /* exec */

  char *cmd_line[4];
  cmd_line[0] = "bash";
  cmd_line[1] = "-c";
  cmd_line[2] = script;
  cmd_line[3] = NULL;
<commit_msg>report proper pid *after* fork;<commit_after>/*  Author:     Makarius

Bash process group invocation.
*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>


static void fail(const char *msg)
{
  fprintf(stderr, "%s\n", msg);
  exit(2);
}


int main(int argc, char *argv[])
{
  /* args */

  if (argc != 3) {
    fprintf(stderr, "Bad arguments\n");
    exit(1);
  }
  char *pid_name = argv[1];
  char *script = argv[2];


  /* setsid */

  if (setsid() == -1) {
    pid_t pid = fork();
    if (pid == -1) fail("Cannot set session id (failed to fork)");
    else if (pid != 0) exit(0);
    else if (setsid() == -1) fail("Cannot set session id (after fork)");
  }


  /* report pid */

  FILE *pid_file;
  pid_file = fopen(pid_name, "w");
  if (pid_file == NULL) fail("Cannot open pid file");
  fprintf(pid_file, "%d", getpid());
  fclose(pid_file);


  /* exec */

  char *cmd_line[4];
  cmd_line[0] = "bash";
  cmd_line[1] = "-c";
  cmd_line[2] = script;
  cmd_line[3] = NULL;

{'fraction_non_alphanumeric': 0.1955, 'fraction_numerical': 0.015, 'mean_word_length': 3.0424242424242425, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2469655', 'n_tokens_mistral': 812, 'n_tokens_neox': 788, 'n_words': 212}