lkml.org 
[lkml]   [1996]   [Jul]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectlinux bug in pclose

Hello Linux Guys !

I have found a strange bugs in linux-2.0.5 !

here is a little program :
==================cut here===================
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>

static void SonIsDead();
static int nbpgm;

main(ac,av)
int ac;
char *av[];
{
int pid;
FILE *comm;

nbpgm = 0;
signal( SIGCHLD, SonIsDead );

if ((pid = fork()) == 0) {
system("xlogo");
exit( 0 );
}
if( pid != -1 ) {
printf("launching xlogo pid = %d\n",pid);
nbpgm ++;
} else {
perror("fork");
exit(1);
}

printf("writing to a pipe\n");
comm = popen( "cat", "w" );
if( comm != NULL ){
fprintf(comm,"aaaaaaaaaaaaaaaaaa\n");
fprintf(comm,"bbbbbbbbbbbbbbbbbb\n");
pclose(comm);
}
printf("end writing to a pipe\n");

printf("waiting son to die\n");

while ( nbpgm ) {
sleep(1);
}
printf("OK\n");
}

static void SonIsDead(){
int pid;

/* sous linux on rearme le signal car ya pas de sigset */
signal( SIGCHLD, SonIsDead );

pid = wait( 0 );

printf("Son %d is dead \n",pid);

if( nbpgm > 0 )
nbpgm--;
}
==================cut here===================

this program fork xlogo (for instance!) and wait for the son to die
by catching SIGCHLD.

in addition , it write some data to a pipe , then close the pipe
and finally wait until the son is dead !


This is working perfectly well on linux-1.2.13 or linux-1.3.100

but on linux-2.0.1 and linux-2.0.5 the pclose is blocked until the
son is dead !!
In addition we got 2 signal SIGCHLD , one with the good pid ,
and one with pid == -1 !

Have Fun !

--
===============================================================================
| _ | dan@lectra.fr |
| __/ _ _ o _ / /_) _ _ / _ | |
| (_/ (_(_ / ) ( (-' / /\ (_) (_ /) (-' | May the source be with |
| | you !! |
===============================================================================


\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.813 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site