setenv por proceso?

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?

Gracias.

preguntado el 01 de febrero de 12 a las 22:02

3 Respuestas

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.

Respondido 02 Feb 12, 03:02

I'm sorry for this event - the response I gave wasn't appropriate for the situation. - Dietmar Kühl

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).

Respondido 02 Feb 12, 03:02

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.

Respondido 02 Feb 12, 15:02

Puedo ver eso setenv() is part of POSIX but I didn't see it in C or C++. - Dietmar Kühl

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.