The UNIX and Linux Forums  


Go Back   O UNIX e Linux Forum > Top Fóruns > Alto Nível de programação
.
google unix.com



Alto Nível de programação Post perguntas sobre C, C + +, Java, SQL, e outras linguagens de programação aqui.

Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
Fio Thread Starter Fórum Respostas Última postagem
Problemas com logadm / syslog em Sol 9 / 10 avronius Sun Solaris 10 11-04-2008 02:24
[Linux] Como faço para executar Até Segfault aslambilal UNIX para Dummies Perguntas & Respostas 1 10-17-2008 09:01
Atingir Ctrl-C ou Ctrl-D sendhilmani123 Programação Shell Script e 2 05-02-2006 06:02
Desabilitar Ctrl-C, Ctrl-D, Ctrl-d em ksh script wtofu AIX 6 06-29-2005 05:41
problemas com o Ctrl-Z, para mudar de plano, fundo yls177 UNIX para Dummies Perguntas & Respostas 9 04-15-2003 01:09

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
Linkback Thread Tools Pesquisar este Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-12-2009
james2432 james2432 is offline
Usuário
  
 

Join Date: Apr 2009
Lugares: 15
2 Problemas: Segfault sobre CTRL + C e syslog () prob

1. Mesmo que eu tenho as alças para o ctrl + c dá um largo segfault
2. syslog não LOG_ERR log evento com log mascarados especificado ou não especificado, ele registra LOG_WARNING no entanto ...


Código:
#include <sys/types.h>  /* include this before any other sys headers */
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <syslog.h>
#include <errno.h>
#include <sys/wait.h>   /* header for waitpid() and various macros */
#include <signal.h>     /* header for signal functions */
#include <stdio.h>      /* header for fprintf() */
#include <unistd.h>     /* header for fork() */
#include <stdlib.h>   
void  ChildProcess(void);                /* child process prototype  */
void  ParentProcess(void);               /* parent process prototype */
#define DAEMON_NAME "mplayerdaemon"
#define PID_FILE "/var/run/mplayerdaemon.pid"

/***********************************************************
  Function: signal_handler
  Description: Handles signals the daemon might receive. 
               Gives the daemon enough time to properly shutdown

  Params: sig : The signal(int) received
 *********************************************************************/
void signal_handler(int sig) {
 
    switch(sig) {
        case SIGHUP:
            syslog(LOG_WARNING, "Received SIGHUP signal.");
            break;
        case SIGTERM:
            syslog(LOG_WARNING, "Received SIGTERM signal.");
            break;
        default:
            syslog(LOG_WARNING, "Unhandled signal (%d) %s", strsignal(sig));
            break;
    }
}

int  main(int argc, char *argv[])
{
#if defined(DEBUG)
    int daemonize=0;
#else
    int daemonize=1;
#endif
    
    // Setup signal handling before we start
    signal(SIGABRT, signal_handler);
    signal(SIGHUP, signal_handler);
    signal(SIGTERM, signal_handler);
    signal(SIGINT, signal_handler);
    signal(SIGQUIT, signal_handler);

    syslog(LOG_INFO, "[INFO] %s daemon starting up",DAEMON_NAME);

#if defined(DEBUG)
        setlogmask(LOG_UPTO(LOG_DEBUG));
        openlog(DAEMON_NAME,LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);
#else
        setlogmask(LOG_UPTO(LOG_INFO));
        openlog(DAEMON_NAME, LOG_CONS, LOG_USER);
#endif

    /* Our process ID and Session ID */
    pid_t pid, sid;

    syslog(LOG_WARNING,"[ERROR] testing error");
    daemonize=0; //for debug purposes only
    if (daemonize) {
        syslog(LOG_INFO, "[INFO] starting the daemon process");


        /* Fork off the parent */
        pid = fork();
        if (pid<0) {
            exit(EXIT_FAILURE);
        }
        /* If we got a good PID, then 
          we can tell the parent to exit*/
        if (pid>0){
            exit(EXIT_SUCCESS);
        }
        /* Child will always have a 0 if successfully created*/

        /* Change umask so that the program will have access to all child files */
        umask(0);

        /* Create a new SID for the child process */
        sid = setsid();
        if (sid<0){
            syslog(LOG_WARNING,"[ERROR] Error while getting new session id, error code : -1");
            exit(EXIT_FAILURE);
        }

        /* Change the current working directory */
        /*
         if ((chdir("/")) < 0){
            syslog(LOG_ERR,"Error while changing directory error code : -1");
             exit(EXIT_FAILURE);
         }

         */

        /* Close out the standard file descriptors 
           Because daemon won't be accepting input from console */
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
        
    }

    while(1){
          int rc=system("ps -C mplayer -opid=");
                        
          rc = WEXITSTATUS(rc); /* Check if mplayer is running */
          printf("I was here pid: %d\n",rc);

        /*if mplayer quits unexpectedly */
        if(rc > 0 ){
           
                 launchmplayer();
                 sleep(2);
              }

     }

    /* if loop breaks daemon exits*/
    syslog(LOG_INFO, "%s daemon exiting",DAEMON_NAME);

    exit(0);
}

void launchmplayer(void)
{
     system("mplayer ~/test.avi");
     return;
}

  #2 (permalink)  
Old 06-16-2009
lagigliaivan lagigliaivan is offline
Usuário
  
 

Join Date: May 2008
Lugares: 45
Oi

O OS / arquitetura que você está usando? Eu tentei usar o Linux e apesar de o código não compilar num primeiro momento, trabalha muito bem e eu não receber um sigsev.

Lembro-me de uma vez tive o mesmo problema, mas ele estava em uma arquitetura diferente para i386.
  #3 (permalink)  
Old 06-16-2009
james2432 james2432 is offline
Usuário
  
 

Join Date: Apr 2009
Lugares: 15
Padrão do kernel do ubuntu 9,04
I386 Archetechure
Reply

Marcadores

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Ligado




Todos os horários são GMT -4. A hora é agora 02:42.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Fóruns Content Copyright © 1993-2009. Todos os Direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0