Sponsored Content
Top Forums Programming how exactly does pclose work in C? Post 302504901 by lilezek on Tuesday 15th of March 2011 05:41:23 PM
Old 03-15-2011
Quote:
Originally Posted by man pclose
The pclose() function waits for the associated process to terminate and
returns the exit status of the command as returned by wait4(2).
Quote:
Originally Posted by man wait4
The wait3() and wait4() system calls are similar to waitpid(2), but
additionally return resource usage information about the child in the
structure pointed to by rusage.
Quote:
Originally Posted by man waitpid
All of these system calls (wait, waitpid, waitid...) are used to wait for state changes in a child
of the calling process, and obtain information about the child whose
state has changed. A state change is considered to be: the child ter‐
minated; the child was stopped by a signal; or the child was resumed by
a signal. In the case of a terminated child, performing a wait allows
the system to release the resources associated with the child; if a
wait is not performed, then the terminated child remains in a "zombie"
state (see NOTES below).
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

2. UNIX for Advanced & Expert Users

pclose returning -1

Hi all, In my application i am trying to select some text & then give it to print. for this i am opening a stream using popen & then later closing using pclose. Now this is working fine in my environment (solaris) but the pclose function is failing at my clients m/c. Even though print is... (3 Replies)
Discussion started by: nimishm123
3 Replies

3. UNIX for Dummies Questions & Answers

cant get this to work

whoami | grep < $1 | echo $1 trying to write a script that finds out who the user is and then takes occurences of that username from a file that is passed as an argument and then displays it (6 Replies)
Discussion started by: iago
6 Replies

4. Linux

How does it work?

Can anyone explain how Graphic LCD (CSTN / STN) work in Unix... From Graphic file thro driver code to display....? Thanks (1 Reply)
Discussion started by: nat123
1 Replies

5. Linux

Come and work for me! (UK)

********nothing too see here!!!****** (2 Replies)
Discussion started by: TonyChapman
2 Replies

6. Shell Programming and Scripting

ls -d does not work

Hi falks, I need to dispaly a list of only directories . As it written in the manual ,the command to do it is 'ls -d'. When i issue 'ls -d' i'm getting: tornado.orca.ent:DB10g :/home/oracle/Create_Database > ls -d . Is anyone have any idea why id does not display directories ,or maybe... (11 Replies)
Discussion started by: nir_s
11 Replies

7. UNIX for Advanced & Expert Users

popen and pclose solved

Hi I am trying to use popen function with wrtie option to give inputs to ftp command. #include "stdio.h" int main(int argv ,char *argc) { int size=0; char *buf; FILE *fp; fp = popen("ftp","w"); while(getline(&buf,&size,stdin) != -1) write(fp,buf);... (0 Replies)
Discussion started by: kumaran_5555
0 Replies

8. IP Networking

NIC will not work, but it did work.

I have a client machine that was built and loaded with SCO UNIX 2.1.3, (yes it is old). The machine worked fine on the closed network that I tested on in my shop. I then had to change it to the network that it would be connected to. Below is the host file, router and subnet mask file that I usually... (0 Replies)
Discussion started by: NC user
0 Replies

9. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

10. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies
PCLOSE(3P)						     POSIX Programmer's Manual							PCLOSE(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
pclose - close a pipe stream to or from a process SYNOPSIS
#include <stdio.h> int pclose(FILE *stream); DESCRIPTION
The pclose() function shall close a stream that was opened by popen(), wait for the command to terminate, and return the termination status of the process that was running the command language interpreter. However, if a call caused the termination status to be unavailable to pclose(), then pclose() shall return -1 with errno set to [ECHILD] to report this situation. This can happen if the application calls one of the following functions: * wait() * waitpid() with a pid argument less than or equal to 0 or equal to the process ID of the command line interpreter * Any other function not defined in this volume of IEEE Std 1003.1-2001 that could do one of the above In any case, pclose() shall not return before the child process created by popen() has terminated. If the command language interpreter cannot be executed, the child termination status returned by pclose() shall be as if the command lan- guage interpreter terminated using exit(127) or _exit(127). The pclose() function shall not affect the termination status of any child of the calling process other than the one created by popen() for the associated stream. If the argument stream to pclose() is not a pointer to a stream created by popen(), the result of pclose() is undefined. RETURN VALUE
Upon successful return, pclose() shall return the termination status of the command language interpreter. Otherwise, pclose() shall return -1 and set errno to indicate the error. ERRORS
The pclose() function shall fail if: ECHILD The status of the child process could not be obtained, as described above. The following sections are informative. EXAMPLES
None. APPLICATION USAGE
None. RATIONALE
There is a requirement that pclose() not return before the child process terminates. This is intended to disallow implementations that return [EINTR] if a signal is received while waiting. If pclose() returned before the child terminated, there would be no way for the application to discover which child used to be associated with the stream, and it could not do the cleanup itself. If the stream pointed to by stream was not created by popen(), historical implementations of pclose() return -1 without setting errno. To avoid requiring pclose() to set errno in this case, IEEE Std 1003.1-2001 makes the behavior unspecified. An application should not use pclose() to close any stream that was not created by popen(). Some historical implementations of pclose() either block or ignore the signals SIGINT, SIGQUIT, and SIGHUP while waiting for the child process to terminate. Since this behavior is not described for the pclose() function in IEEE Std 1003.1-2001, such implementations are not conforming. Also, some historical implementations return [EINTR] if a signal is received, even though the child process has not terminated. Such implementations are also considered non-conforming. Consider, for example, an application that uses: popen("command", "r") to start command, which is part of the same application. The parent writes a prompt to its standard output (presumably the terminal) and then reads from the popen()ed stream. The child reads the response from the user, does some transformation on the response (pathname expan- sion, perhaps) and writes the result to its standard output. The parent process reads the result from the pipe, does something with it, and prints another prompt. The cycle repeats. Assuming that both processes do appropriate buffer flushing, this would be expected to work. To conform to IEEE Std 1003.1-2001, pclose() must use waitpid(), or some similar function, instead of wait(). The code sample below illustrates how the pclose() function might be implemented on a system conforming to IEEE Std 1003.1-2001. 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); } FUTURE DIRECTIONS
None. SEE ALSO
fork(), popen(), waitpid(), the Base Definitions volume of IEEE Std 1003.1-2001, <stdio.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 PCLOSE(3P)
All times are GMT -4. The time now is 02:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy