Linux C System

Source: Internet
Author: User

Linux C system is used to execute shell commands in programs.

Usage

# Include <stdlib. h> <br/> // function form <br/> INT system (const char * string );

Function Description
System () calls fork () to generate sub-processes. The sub-process calls/bin/sh-C string to execute the command represented by the string parameter, after the command is executed, the original called process is returned. The sigchld signal is temporarily shelved during system () calls, while the SIGINT and sigquit signals are ignored.
Return Value
If system () fails to call/bin/sh, 127 is returned, and-1 is returned for other causes of failure. If the string parameter is a null pointer, a non-zero value is returned. If system () is successfully called, the return value after the shell command is executed is returned. However, the returned value may also be 127 returned when system () fails to call/bin/sh, therefore, it is best to check errno again to confirm the execution is successful.
Additional instructions
Do not use system () when writing programs with SUID/SGID permissions. System () inherits environment variables, which may cause system security problems.

Example

# Include <stdlib. h> <br/> main () <br/> {<br/> system ("LS-Al/etc/passwd/etc/shadow "); <br/>}< br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.