Linuxでc++を使用してshellコマンドを呼び出す


1:system()
宣言:
extern int system (const char *__command) __wur;
    :     fork()     ,           ,  system  ,SIGG
HID      ,  SIGINT SIGQUIT     。
     ,  system()   /bin/sh      127,        -

2:popen
extern FILE *popen (const char *__command, const char *__modes) __wur;

popen()    fork()     ,         /bin/sh -c
     command   。  type   “r”    ,“w”
    。   type ,popen()              
          ,          。       
                             
    。  ,        (FILE*)          
 ,  fclose()  。
3、  vfork()     ,    exec   

         vfork  , fork     : 
  
 
   

fork vfork
1. fork ; vfork , exec exit ,
2. fork ; vfork , , , exec exit , 。

exit(0), _exit(0)。 _exit(0) , I/O 。 exit(0) I/O 。

#include
main()
{
char * argv[ ]={“ls”,”-al”,”/etc/passwd”,(char*) };

if(vfork() = =0)
{
execv(“/bin/ls”,argv);
}else{
printf(“This is the parent process
”);
}
}

4   exec   ,      ,    csdn