0

in the documention of pclose function there is a part of code which illustrates how the pclose() function might be implemented

int pclose(FILE *stream)

{
    int stat;
    pid_t pid;


    pid = <pid for process created for stream by popen()>
    (void) fclose(stream);
    while (waitpid(pid, &stat, 0) == -1) {
        if (errno != EINTR){
            stat = -1;
            break;
        }
    }
    return(stat);
}

so i'm interesting , form where he gets "pid for process created for stream by popen()". is there some place where this value is stored?

zapredelom
  • 1,009
  • 1
  • 11
  • 28
  • 1
    That is very OS specific, I think. – Kiril Kirov Mar 27 '13 at 09:45
  • http://stackoverflow.com/questions/9462442/c-get-pid-of-process-opened-with-popen – kugg Mar 27 '13 at 09:50
  • thank's @kugg , it's the one of solution of my problem, which I already implemented, but it would be good to use standard function and get that pid but as I understand from comments and answers, it is not possible. – zapredelom Mar 27 '13 at 09:56
  • If it helps you may want to look at this [implementation](http://stackoverflow.com/questions/548063/kill-a-process-started-with-popen) – kugg Mar 27 '13 at 09:58

1 Answers1

2

From some internal state owned by the library that implements popen() and pclose(). Most probably it will be stored as a field in the (internal) FILE structure.

unwind
  • 391,730
  • 64
  • 469
  • 606