spawnl

spawnl是创建并且执行一个新的进程的函数。

函数名: _spawnl

所属库: process.h

功 能: 创建并且执剃热汗行一个新的进程

函巩己罪体数原型:int _spawnl( int mode, const char *pathname, const char *arg0, const char *arg1, … const char *argn, NULL );

相关函数:_spawnle、_spawnlp、_spawnlpe、_wspawnle、_wspawnlp、_wspawnlpe、_wspawnl

程序例1

#include <process.h>

#include <stdio.h>

#include <stdlib.h>

int main(void)

{

int result;

result = spawnl(P_WAIT, "tcc.exe", NULL);

if (result == -1)

{

perror("Error from spawnl");

exit(1);

}

return 0;

}

程序例2

//这个例子中耻束祖显示了8个spawn函数的用洪纸兵法:

#include <stdio.h>欢促设捆

#include <process.h>洪禁举

#include <stdlib.h>

char *my_env[] = {"THIS=environment will be","PASSED=to child.exe by the","_SPAWNLE=and","_SPAWNLPE=and","_SPAWNVE=and","_SPAWNVPE=functions",NULL};

int main( int argc,char *argv[] )

{

char *args[4];

args[0] = "child";

args[1] = "spawn??";

args[2] = "two";

args[3] = NULL;

if(argc <= 2)

{

printf( "SYNTAX: SPAWN <1-8> <childprogram>\n" );

exit( 1 );

}

switch (argv[1][0])

{

case '1': _spawnl( _P_WAIT, argv[2], argv[2], "_spawnl", "two", NULL );break;

case '2': _spawnle( _P_WAIT, argv[2], argv[2], "_spawnle", "two", NULL, my_env ); break;

case '3': _spawnlp(_P_WAIT, argv[2], argv[2], "_spawnlp", "two", NULL ); break;

case '4': _spawnlpe( _P_WAIT, argv[2], argv[2], "_spawnlpe", "two"炒拜, NULL, my_env ); break;

case '5': _spawnv( _P_OVERLAY, argv[2], args ); break;

case '6': _spawnve( _P_OVERLAY, argv[2], args, my_env ); break;

case '7': _spawnvp( _P_OVERLAY,argv[2], args );break;

case '8': _spawnvpe( _P_OVERLAY, argv[2], args, my_env ); break;

default: printf( "SYNTAX: SPAWN <1-8> <childprogram>\n" );exit( 1 );

}

printf( "from SPAWN!\n" );

return 0;

}

相关词汇