Thread: Porting to Linux?

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON

    Porting to Linux?

    I'm porting an ancient C program to Linux and I have 2 versions of this function, one for BSD and one for SYS V.
    I'm not sure if either is appropriate for Linux, but the only real difference is the call to wait() (the SYS V version uses 'union wait status' instead of 'int status'). Here's the BSD version:
    	spawnvp( mode, path, argv )
    		int mode;
    		char *path;
    		char *argv[];
    		int pid;
    		int status;
    		fflush( stdout );
    		fflush( stderr );
    		signal(SIGCHLD, SIG_DFL);
    		switch ( pid = fork() ) {
    		case -1:	/* error  */
    			return -1;
    		case 0:		/* child  */
    			exit( execvp( path, argv ) );
    		default:	/* parent */
    			while ( wait( &status ) != pid )
    			return status ? -1 : 0;
    I can't see any reason why this wouldn't work fine on Linux, but then again, I never use those fork(), execvp(), signal()... functions.
    Will this work as expected (which of course is undocumented, so I can only guess)?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Looks ok from a brief view - have you tried to compile it? [Not that will guarantee that it works right, but it's a good start if it compiles - there's a chance then...]

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    Look fine to me. You might consider eliminating the while-loop around the call to wait() by calling waitpid() instead, but it's no big deal and using wait() is more primitive and therefore more portable.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    Thanks. I guess I'll just use it like that and see how it goes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread and socket porting from Linux to Windows
    By mynickmynick in forum C Programming
    Replies: 2
    Last Post: 07-18-2008, 06:57 AM
  2. Porting from VC6 to Linux Fedora core 5
    By g4j31a5 in forum C++ Programming
    Replies: 17
    Last Post: 08-08-2006, 01:59 AM
  3. wxWidgets, porting from Linux to PDA
    By BobS0327 in forum Tech Board
    Replies: 0
    Last Post: 05-16-2006, 08:25 AM
  4. Replies: 1
    Last Post: 10-18-2005, 10:20 AM
  5. Porting the NES emulator from DOS to Linux
    By billholm in forum Game Programming
    Replies: 14
    Last Post: 08-03-2002, 01:48 AM