Available in

(3) (3)/de (3)/es (3)/fr (3)/ja (3)/ko (3)/pt (3)/tr (3c) (3posix) (3w) (4)

TOC

SYSTEM(3)                                                            SYSTEM(3)



system - shell

#include <stdlib.h>

       int system (const char * string);

system()

       /bin/sh -c string

       string
          ,   .
         , SIGCHLD
        , SIGINT

       SIGQUIT
        .



/bin/sh

       execve()
        ,   127 ,    -1,
        .

       string

       NULL, system()
        shell   0   ,   0  .

       system()
           wait    .

ANSI C, POSIX.2, BSD 4.3

       libc
       system()
             .
               .

       system()
             .(:   !)

       int my_system (const char *command) {
           int pid, status;

           if (command == 0)
               return 1;
           pid = fork();
           if (pid == -1)
               return -1;
           if (pid == 0) {
               char *argv[4];
               argv[0] = "sh";
               argv[1] = "-c";
               argv[2] = command;
               argv[3] = 0;
               execve("/bin/sh", argv, environ);
               exit(127);
           }
           do {
               if (waitpid(pid, &status, 0) == -1) {
                   if (errno != EINTR)
                       return -1;
               } else
                   return status;
           } while(1);
       }

       suid  sgid system()
         .
        .

       exec(3)
         .  execlp(3)

       execvp(3)

       system()

       /bin/sh

       bash
        2  suid  sgid      .
        bash 2    .  (Debian sh
            bash .)

       /bin/sh
            ;   .  ISO C  , POSIX.2    0     .
        shell     .

         127 shell  .  execve()
           ;

       errno
        .

sh(1),
       signal(2), exec(3)

 <skyeyes [AT] soback.net>, 2001 3 12
GNU                                1998 5 11                         SYSTEM(3)

COMMENTS

Add your comment here. Whitespace and linebreaks are preserved. URLs are linked automatically.
CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.