linux - How can I verify in my C program that four terminals are currently open? -


so i'm going preface saying homework project in class. supposed determine user opened 4 terminal windows before running program, , have determining if can open 4 terminal number buffers /dev/pts/ read-only. have save these first 4 buffers can open them again write terminals. know how open files fopen issue terminals aren't open anymore still show , accessible. know pretty frowned upon ask homework i've been working @ hours , don't want written me want direction. how can check there 4 terminals open using method have use? here's code maybe 1 of y'all can see i'm doing wrong.

#include <stdio.h> #include <stdlib.h>  #define maxline 100  int main(){     int i, ptsnum[4], ptscount = 0;     file *fp;     char ptsname[20];      for(i = 0; < 20; i++){         // append terminal number end of buffer name         sprintf(ptsname, "/dev/pts/%d", i);         // try open file         if((fp = fopen(ptsname, "r")) != null){             // save terminal number if buffer exists             ptsnum[ptscount] = i;             ptscount++;             fclose(fp);         }     }  return 0; } 

well, try open terminals, once them counted, fclose(3) them, in case want them open, don't last fclose(3) @ end of loop.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -