Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top