示例#1
0
文件: main.c 项目: samsymons/TDB
void begin_debugging(const char *name) {
  pid_t child_pid = fork();

  if (child_pid == 0) {
    // If this is the child process, then begin tracing and executing it.
    execute_child_process(name);
  }
  else if (child_pid > 0) {
    // For the parent process, start up the debugger and wait for the child.
    start_debugger(child_pid);
  }
  else {
    puts("Failed to fork; exiting");
    exit(1);
  }
}
示例#2
0
void run(char *path, int argc, char* argv[], int display, int wait, char* ext)
{
    int file_count, children_file_count;
    char *entry_path;
    DIR *dir;
    dirent_t *entry;

    file_count = 0;
    dir = opendir(path);

    if(dir == NULL) {
        perror("Invalid directory name\n");
        exit(-1);
    }

    while(entry = readdir(dir)) {
        if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue;

        if(entry->d_type == DT_DIR) {
            entry_path = malloc(strlen(path) + strlen(entry->d_name) + 2);
            sprintf(entry_path, "%s/%s", path, entry->d_name);

            insert_argv_path(argc, argv, entry_path);
            execute_child_process(entry_path, argv);

            free(entry_path);
        } else if(entry->d_type == DT_REG) {
            if(ext == NULL || strcmp(get_filename_ext(entry->d_name), ext) == 0) {
                file_count += 1;
            }
        }
    }

    if(wait) sleep(15);

    children_file_count = collect_children_file_count();

    if(display) {
        printf("Directory: %s \nFile count: %d\nChildren file count: %d\n-----------\n", path, file_count, children_file_count);
    }

    closedir(dir);
    exit(file_count + children_file_count);
}