What information is inherited between the Java parent-child processes?

Source: Internet
Author: User

Because of the test environment under Linux, the sharing mechanism of variables in Linux environment:

About Export
1. The system environment variables in a shell are copied to the sub shell (with the variables defined by export).
2. The system environment variable in a shell is valid only for the shell or its child shell, and the variable disappears at the end of the shell (and cannot be returned to the parent shell).
3. A variable that is not defined by export is valid only for the shell, and the child shell is also invalid.

In Java, Java provides a static method of the System class getenv () and GetProperty () to return system-related variables and attributes when a program needs to use operating system-related variables such as file delimiters and line breaks. The variables returned by the Getenv method are mostly system-related, and the variables returned by the GetProperty method are mostly related to Java programs.

System Properties and environment variables are mappings between names and values. Both mechanisms can be used to pass user-defined information to the Java process. Environment variables produce more global effects because they are not only visible to Java child processes, but are visible to all child processes that define them. On different operating systems, their semantics are subtly different, for example, case-insensitive. Therefore, environment variables are more likely to have unexpected side effects. Use System properties as much as possible in your program. Environment variables should be used when global effects are required, or when external system interfaces require the use of environment variables (such as PATH).

How Java starts the subprocess:

Public Process exec (string[] cmdarray, string[] ENVP throws IOException executes the specified

command and arguments In a separate process with the specified environment.

Given an array of strings cmdarray, representing the tokens of-a command line, and an array of strings envp, representing "Environment" variable settings, this is creates a new process in which to execute the specified command.

<strong>if envp is null, the subprocess inherits the environment settings of the current process.</strong>

Ref:http://stackoverflow.com/questions/8997643/launch-a-child-process-from-java-that-doesnt-inherit-files-ports-on-unix


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.