Subject: Re: is it possible to program for background?
From: [email-masked] (Michael Hirmke)

12 Dec 1998 19:03:06 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: [email-masked]

Hi,

>Hi there!
>
>Is it possible to make a program to run on background?

Yepp, works with fork as expected.

>I'm playing with fork but i can't get it to work.
>I want the program to work on both, unix and windows...

I attach a small code snippet from one of my programs - perhaps it
helps. Sorry for a few comments being in German.

[...]
>Thank you
>Joaquin Grech

Bye.
Michael.

------------------------< snip snip snip >-----------------------------
void fCalluucico( char *sRemote ) {
  struct stat statBuf;
  char *sLogHist = TAYLOR_LOGHIST;
  pid_t pid_uucico = -1;
  pid_t pid_uulog = -1;
  int status_uucico;

  errno = 0;
  if( stat( sUUCICO, &statBuf ) != 0 )
    fError( errno, TAYLOR_ERR_EXEC );

  // jetzt keinesfalls unterbrechen lassen !
  signal( SIGINT, fIntHandlerIgnore );
  signal( SIGQUIT, fIntHandlerIgnore );

  pid_uucico = fork();
  switch( pid_uucico ) {
    case -1:
      fError( errno, TAYLOR_ERR_FORK );
      break;
    case 0:
      if( iVerbose > 9 ) {
        fprintf( OUT, asMessages[ TAYLOR_NO_UUCICO ] );
        exit( 0 );
      } else {
        if( iVerbose > 0 ) {
          fprintf( OUT, asMessages[ TAYLOR_UUCICO ] );
          fflush( OUT );
        } // Ende if( .. )
        sleep( 2 );
        // ============================================================
        // -D            = Do not detach from the controlling terminal.
        // -I sTAYLORCfg = Main configuration file.
        // -q            = Do not start the `uuxqt' daemon when finished.
        // -x abnormal   = Debug type.
        // -S sRemote    = force to call the specified system.
        // ============================================================
        errno = 0;
        execl( sUUCICO, sUUCICO,
               "-D",
               "-I",
               sTAYLORCfg,
               "-q",
               "-x",
               "abnormal",
               "-S",
               sRemote,
               (char *)0 );
        fError( errno, TAYLOR_ERR_EXEC );
      } // Ende if( .. )
      break;
    default:
      if( iVerbose > 0 ) {
        if( stat( sUULOG, &statBuf ) == 0 ) {
          pid_uulog = fork();
          switch( pid_uulog ) {
            case -1:
              fprintf( OUT, asMessages[ TAYLOR_ERR_UULOG ],
                            sUULOG, strerror( errno ), errno );
              fflush( OUT );
              break;
            case 0:
              fprintf( OUT, asMessages[ TAYLOR_UULOG ], sLogHist );
              errno = 0;
              execl( sUULOG, sUULOG,
                     "-I",
                     sTAYLORCfg,
                     "-n",
                     sLogHist,
                     "-f",
                     sRemote,
                     (char * )0 );
              fprintf( OUT, asMessages[ TAYLOR_ERR_UULOG ],
                            sUULOG, strerror( errno ), errno );
              fflush( OUT );
              exit( 0 );
              break;
            default:
              break;
          } // Ende switch( .. )
        } else {
          fprintf( OUT, asMessages[ TAYLOR_ERR_UULOG ],
                        sUULOG, strerror( errno ), errno );
          fflush( OUT );
        } // Ende if( .. )
      } // Ende if( .. )

      // wir warten auf's Christkind, aeh - den uucico
      waitpid( pid_uucico, &status_uucico, 0 );

      if( pid_uulog != -1 ) {
        sleep( 1 );
        kill( pid_uulog, SIGINT );
      } // Ende if( .. )

      // wenn der User meint, darf er jetzt wieder :)
      // ach nee, lieber doch nicht - gibt nur probleme 8-|
      signal( SIGINT, fIntHandlerIgnore );
      signal( SIGQUIT, fIntHandlerIgnore );

      if( WIFEXITED( status_uucico ) ) {
        if( WEXITSTATUS( status_uucico ) != 0 ) {
          fError( ( WEXITSTATUS( status_uucico ) ) * -1, TAYLOR_ERR_UUCICO );
        } // Ende if( .. )
      } // Ende if( .. )
      break;
  } // Ende switch( .. )

} // Ende fCalluucico( .. )
------------------------< snip snip snip >-----------------------------

--
Michael Hirmke           | Telefon +49 (911) 557999
Georg-Strobel-Strasse 81 | FAX     +49 (911) 557664
90489 Nuernberg          | E-Mail  mailto:[email-masked]
                         | WWW     http://aquarius.franken.de/
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".