コード例 #1
0
END_TEST

START_TEST(test_trace_account_count)
{
  int status = trace_open("test/4_2_10.trace");
  ck_assert_msg(status != -1, "trace_open should not return -1 if the file does exists");
  int account_cnt = trace_account_count();
  ck_assert_msg(account_cnt == 2, "account count should be 2, received %d", account_cnt);
}
コード例 #2
0
ファイル: treader.c プロジェクト: jmccaffs/Systems
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("usage: %s trace_file\n", argv[0]);
    exit(1);
  }

  int result = trace_open(argv[1]);
  if (result == -1) {
    printf("%s: could not open %s\n", argv[0], argv[1]);
    exit(1);
  }

  printf("number of ATMs: %d\n", trace_atm_count());
  printf("number of accounts: %d\n", trace_account_count());

  byte cmd[MESSAGE_SIZE];
  while (trace_read_cmd(cmd) != 0) {
    cmd_dump("TREADER", 0, cmd);
  }

  trace_close();
  
  return 0;
}
コード例 #3
0
ファイル: banksim.c プロジェクト: Timodie/Projects-in-C
int main (int argc, char *argv[]) {
  if (argc != 2) {
    printf("usage: %s trace_file\n", argv[0]);
    exit(1);
  }

  int result        = 0;
  int atm_count     = 0;
  int account_count = 0;

  // open the trace file
  result = trace_open(argv[1]);
  if (result == -1) {
    printf("%s: could not open file %s\n", argv[0], argv[1]);
    exit (1);
  }

  // Get the number of ATMs and accounts:
  atm_count     = trace_atm_count();
  account_count = trace_account_count();
  trace_close();

  // Setup bank pipes:
  int bankfd[2];
  pipe(bankfd);

  // This is a table of atm_out file descriptors. It will be used by
  // the bank process to communicate to each of the ATM processes.
  int atm_out_fd[atm_count];

  // TODO: ATM PROCESS FORKING
  // START YOUR IMPLEMENTATION
  for(int i =0; i < atm_count; i++){
    int atmfd[2];
    pipe(atmfd);
     atm_out_fd[i] =atmfd[1];

    if(fork()== 0){
      close(atmfd[1]);
      close(bankfd[0]);
      int result = atm_run(argv[1],bankfd[1],atmfd[0],i);
      if(result != SUCCESS){

        error_print();

      }

    else{
      close(atmfd[0]);
    }
    exit(0);
  }
}
  // END YOUR IMPLEMENTATION


  // TODO: BANK PROCESS FORKING
  // START YOUR IMPLEMENTATION
//pid_t pid2 = fork();
if(fork() == 0){
  close(bankfd[1]);
  bank_open(atm_count,account_count);
  int result =run_bank(bankfd[0],atm_out_fd);
  if(result != SUCCESS){

    error_print();
  }
    bank_dump();
    bank_close();
    exit(0);

}
  // END YOUR IMPLEMENTATION

  // Wait for each of the child processes to complete. We include
  // atm_count to include the bank process (i.e., this is not a
  // fence post error!)
  for (int i = 0; i <= atm_count; i++) {
    wait(NULL);
  }

  return 0;
}