delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/01/17/14:39:12

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Wed, 17 Jan 2001 21:37:29 +0200
Message-Id: <200101171937.VAA10622@linux.>
From: "Ehud Karni" <ehud AT unix DOT simonwiesel DOT co DOT il>
To: cygwin AT cygwin DOT com
Subject: Re: (detached) background (console) processes
In-reply-to: <3A6314C4.F08C2845@iki.fi> (message from Kaatunut on Mon, 15 Jan
2001 17:18:28 +0200)
Organization: Simon & Wiesel Insurance agency
Reply-to: ehud AT unix DOT simonwiesel DOT co DOT il
References: <3A6314C4 DOT F08C2845 AT iki DOT fi>
X-Mailer: Emacs 20.7.1 rmail (send-msg 1.104)
MIME-Version: 1.0

On Mon, 15 Jan 2001 17:18:28 +0200, Kaatunut <kaatunut AT iki DOT fi> wrote:
> 
> How do I create a console (well, actually, console-less) process that I
> can leave running at background- that is, no need for terminal? Under
> unix, I would just do

If you add the switch -mwindows to your gcc compilation (DO NOT change
your main to winmain !) it will make an exe that will be without console
when started from windows command line (what is really happens is that
the program has invisible window). You'll get the following warning
    /usr/lib/gcc-lib/i686-pc-cygwin/2.95.2-6/../../../../i686-pc-cygwin/bin/ld: warning: cannot find entry symbol _WinMainCRTStartup; defaulting to 00401000
that you should ignore.

At the end is of a small program that can run any program/script without
a visible window.

As for Mumit Khan <khan AT NanoTech DOT Wisc DOT EDU> remark:
>
> Note that there is more to making a program run in the background
> correctly than just using fork, and that applies to all Unix-like
> systems. You'll need to do deal session leaders and controlling ttys
> and so on (different flavors such as SysV4 and BSD do things a bit
> differently, and POSIX uses a combination of the two approaches).

Although I use `setsid ();' when needed, it is not relevant here.

Ehud.



/* run-nw.c: run any script or program with no visible window
                                                 27/12/00  */

#include <stdio.h>                         /* standard io library */
#include <stdlib.h>                        /* standard library */
#include <unistd.h>                        /* sleep , fork & exec */
#include <string.h>                        /* standard string library */
#include <errno.h>

int main ( int argc, char *argv[] )
{
char cmd [32000 ] = "" ;                   /* user command */
char *nargs [4 ] = { "/bin/bash" ,  "-c" , cmd , NULL } ;   /* execute with login /bin/bash */
int i = 1 ;

   putenv ( "BASH_ENV=/etc/bash.rc" ) ;    /* ensure bash reads my global env changes */

   while ( i < argc )                      /* do for all "real" args */
   {
       strcat ( cmd , "\"" ) ;             /* add quote before */
       strcat ( cmd , argv [ i ] ) ;       /* add the argument */
       strcat ( cmd , "\" " ) ;            /* add closing quote */
       i ++ ;
   }

   fprintf ( stderr , "Command is: |%s|\n" , cmd ) ;

   execv ( "/bin/bash" , nargs ) ;         /* exec sub command */

/* we should never reach here */
   fprintf ( stderr , "Execute failed, error = %d\n" , errno ) ;
   return ( 0 ) ;                          /* exit with no error */
}
/*==========================================================================*/

Compiled by:
gcc run-nw.c -O2 -o run-nw -static -Wall -Wno-format -Wstrict-prototypes -Wmissing-prototypes -mwindows


-- 
 @@@@@@ @@@ @@@@@@ @    @   Ehud Karni  Simon & Wiesel  Insurance agency
     @    @      @  @@  @   Tel: +972-3-6212-757    Fax: +972-3-6292-544
     @    @ @    @ @  @@    (USA)  Fax  and  voice  mail:  1-815-5509341
     @    @ @    @ @    @        Better     Safe     Than     Sorry
 http://www.simonwiesel.co.il    mailto:ehud AT unix DOT simonwiesel DOT co DOT il

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019