SHARE
TWEET

Untitled

a guest May 19th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void close_pipes(int id) {
  2.     for (int i = 1; i < proc_cnt; i++) {
  3.         for (int j = 0; j < proc_cnt; j++) {
  4.             int tmp_read = procs[i].pipes[j].read;
  5.             int tmp_write = procs[i].pipes[j].write;
  6.             if(i==j)
  7.                 continue;
  8.             if (i == id) {
  9.                 close(procs[i].pipes[j].read);
  10.                 fprintf(p_pipes_log, "CLOSED READ-end (%d) pipe FOR procs %d -> %d\n", tmp_read, i, j);
  11.             }
  12.             else if (j == id) {
  13.                 close(procs[i].pipes[j].write);
  14.                 fprintf(p_pipes_log, "CLOSED WRITE-end (%d) pipe FOR procs %d -> %d\n", tmp_write, i, j);
  15.             }
  16.             else {
  17.                 if(j==procs[i].id) continue;
  18.                 close(procs[i].pipes[j].read);
  19.                 close(procs[i].pipes[j].write);
  20.                 fprintf(p_pipes_log, "CLOSED WRITE-end (%d) pipe FOR procs %d -> %d\n", tmp_write, i, j);
  21.                 fprintf(p_pipes_log, "CLOSED READ-end (%d) pipe FOR procs %d -> %d\n", tmp_read, i, j);
  22.             }
  23.         }
  24.     }
  25. }
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top