Because there is no cocoa nstask in iOS, executing the shell in the Cocoa Touch SDK can only call the int system (const char * string) with systems, for example: System ("LS"); note system is the C function So the parameters do not use nsstring; function library:include<stdlib.h>
System (execute shell command)
Related functions
Fork,execve,waitpid,popen
Table header File
#i nclude<stdlib.h>
Defining functions
int system (const char * string);
Function description
System () calls fork () to produce a child process that calls the/BIN/SH-C string to execute the command represented by the argument string string, which returns the process that was originally called when execution is complete. The SIGCHLD signal is temporarily shelved while the system () is being called, and the SIGINT and sigquit signals are ignored.
return value
=-1: Error occurred
= 0: The call succeeds but no child processes appear
>0: ID of the child process that successfully exited
If system () fails when calling/bin/sh, it returns 127, and other failure reasons return-1. If the argument string is a null pointer (NULL), a non-0 value of > is returned. If the system () call succeeds, the return value after executing the shell command is returned, but this return value may also be 127 of the return of the system () call to/bin/sh failure, so it is better to check the errno again to confirm that the execution was successful. If fork () fails to return 1: An error occurs if EXEC () fails, indicating that the shell cannot be executed, and the return value is equivalent to the shell executing exit (127) If execution succeeds then returns the terminating state of the child shell if system () is calling/bin/ SH fails to return 127, other failure causes return-1. If the argument string is a null pointer (NULL), a non-0 value of > is returned. If the system () call succeeds, the return value after executing the shell command is returned, but this return value may also be 127 of the return of the system () call to/bin/sh failure, so it is better to check the errno again to confirm that the execution was successful. Additional Instructions
Do not use System () when writing programs with Suid/sgid permissions, and System () inherits environment variables, which can cause system security issues through environment variables.
Example
#i nclude<stdlib.h>
Main ()
{
System ("Ls-al/etc/passwd/etc/shadow");
}
Execution Result:-rw-r--r--1 root root 705 Sep 3 13:52/etc/passwd
-R---------1 root root 572 Sep 2 15:34/etc/shado example 2:char tmp[];
sprintf (tmp, "/bin/mount-t vfat%s/mnt/usb", Dev);
System (TMP);
where Dev is/dev/sda1.
IOS, iphone call shell script