system () receives a string parameter, and regard it as the command execution
E.g:
system ( "dir D:") to print the contents of the disc D
system ( "gedit") to start the editor in linux
system ( "say 'End of line'") to read the text on mac
II. Use elec () system calls
elec function is located unistd.h header file, function call when the process is successful, the system will stop running the current program, to run the program call.
elecl () = parameter list
elecle () = + environment variable parameter list
eleclp () = PATH search parameter list +
elecv () = parameter array
elecve () = + environment variable parameter array
elecvp () = + a search parameter array PATH
When using elec () function should use NULL terminated argument list
May be used getenv () function reads the environment variables
Three variables .errno
errno variable is defined in global variables errno.h
exec () function call will return -1 error, system error while calling again errno variable to the error code
standard error of errno code:
EPERM = 1 operation is not allowed
ENOENT = 2 no such file or directory
The process is not ESRCH = 3
puts(strerrot(errno));
IV. Use fork () cloning process
Use fork () function to copy the current process
After a successful run exec () will replace the current process, using the fork function to copy the current process and run the exec create a child process, the parent process to facilitate the realization of the original program cycle
Instructions:
pid_t pid=fork()
fork returns an integer as the child returns 0, the parent process returns a positive number, the parent will receive the child process identifier
pid_t function is used to store the process identifier
Use fork () + exec () combined, create and run a separate process, not only to make better use of existing software, but also improve the performance of the program.