 
			
				01/04/2008, 14:50
			
			
			     |  
      |    |    |    Fecha de Ingreso: abril-2008  
						Mensajes: 6
					  Antigüedad: 17 años, 7 meses Puntos: 0     |        |  
  |      Re: Señales en c bajo linux, AYUDA POR FAVORRR!        Gracias!; mira he corregido el código un poco, estoy mas o menso en las misma, pero mas o menso intento utilizar el sprintf de manera correcta(creo...) e implemente lo que me dijiste de las señales SIGUSR1 y y SIGTERM, nose, puedes echarle un ojo porfas!!!!!?   
GRACIAS!         
#include <errno.h> 
#include <fcntl.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <unistd.h> 
#include <math.h> 
#include <signal.h> 
#include <sys/types.h> 
#include <sys/stat.h>     
void SIGUSR1Handler(int sig){ 
   printf("Se ha recibido señal: %d SIGUSR1, continuo, escribir un nuevo nombre de archivo \n",sig1);   
}   
void SIGTERMHandler(int sig){ 
   printf("Se termina la ejecucion de este prog"); 
   exit(0);   
}   
void error (char *m) { 
	write(2,m,strlen(m)); 
	write(2,"\n",1); 
	write(2,strerror(errno),strlen(strerror(errno))); 
	exit(1); 
}             
main(int argc, char *argv[]) 
{ 
	int señal; 
	struct stat buf;   
	stat ("fichero.txt", &buf);   
	char filen[_MAX_PATH];  
        char cad[50]; 
	int res; 
	int lee; 
	int i;   
   	signal(SIGTERM,SIGTERMHandler); 
        signal(SIGUSR1,SIGUSR1Handler);   
	for (i=1; i < argc ; i++)     
	sprintf ("Nombre del archivo: "); 
        gets (filen);      
	if( (filen = open( argv[1], O_RDWR )) == -1 ) 
		{ 
			perror( "open" ); 
			exit( -1 ); 
		}     
	while( (lee = read( filen, buffer, SIZE )) != 0 ) 
	{ 
		write( STDOUT, buffer, lee ); 
	}   
	close( fd );   
	return 0; 
}     
	if (write (1, "SI existe el archivo\n", strlen("SI existe el fichero\n")) < 0) 
		error("Error de escritura stdout");     
	{ 
	 sprintf("%s\n",argv[0]);   
		if ( stat(argv[i], &buf) == -1 ) 
		{ 
			perror(argv[0]); 
			exit(-1); 
		} 
		else sprintf  
		{ 
			sprintf(cad,"Tamaño del archivo %s %d bytes.\n",argv[0],buf.st_size); 
			sprintf(cad,"Propietario %s .\n", argv[0], buf.st_uid); 
			sprintf(cad,"Tipo de Fichero %d\n", buf.st_mode); 
			}       
	else 
	{		sprintf(cad,"NO existe el archivo\n");   
			pause();     
		if (signal(SIGUSR1,SIGUSR1Handler); < 0) 
			{error("error"); 
 			else 
			(siganl(SIGTERMHandler); <0) 
				error("error");	   
				}     
			kill(getpid(),señal); 
               		exit(0);     
} 
} 
};     
N           |