This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: is it possible to program for background?


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:mh@mike.franken.de
                         | WWW     http://aquarius.franken.de/
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]