문제

I m assing file name dynamically using setenv as folows:

setenv("file.name",filename.c_str,1);

I m curious if this is per process?

If i have multiple processes running this code but taking different file names, would there be any collisions?

Lets say I have process 1

setenv("file.name",filename1.c_str,1);  

and process 2

setenv("file.name",filename1.c_str,1);  

would i have any problems doing this?

Thanks.

도움이 되었습니까?

해결책

The environment you set with setenv() is per process. Essentially it is just a memory area in your process. At least, this is what does on UNIX systems. Unlike getenv() it isn't part of either the C or the C++ standard but it is part of POSIX. What it does on non-POSIX systems, if it exists, may be something different.

다른 팁

Environment variables are platform specific. I don't think setenv() works with Windows, so assuming you are talking about a program running on Linux, you should be fine. setenv() sets environment variables with process scope (and of course shared amongst forked threads).

To my knowledge, on all modern operating systems, each process has a seperate environment block which is usually constructed when the process is created. (e.g. during NtCreateProcess() on a Windows system) or the equivalent for Linux/Unix/Other. _putenv() will work on Windows wheras setenv() will work on Linux/Unix.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top