Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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" 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 Content-Type: text/plain; charset=iso-8859-8 Content-Transfer-Encoding: 7bit On Mon, 15 Jan 2001 17:18:28 +0200, Kaatunut 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 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 /* standard io library */ #include /* standard library */ #include /* sleep , fork & exec */ #include /* standard string library */ #include 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