Spartacus92
Spartacus92

Reputation: 51

Should the handle returned from _spawnv be closed?

Do I need to call closeHandle() on the handle from _spawnv()?

Also, is the refcount for the handle of a new process incremented when I call _spawnv()?

And, if it is incremented, then wont the process go into a linux like "zombie" state once it terminates?

Upvotes: 2

Views: 80

Answers (2)

Harry Johnston
Harry Johnston

Reputation: 36318

If you don't need the handle, you should close it. However, the consequences for failing to do so are slight, unless you are spawning a great many processes. The kernel will have to retain the process object (I presume this is roughly analogous to a zombie process in UNIX) but there is no fixed limit on the number of process objects and a terminated process only requires a small amount of memory in the kernel. Once your process exits, the leaked resources will be cleaned up automatically.

As for the reference count of the handle, there's no such thing. Handles are not reference counted.

Upvotes: 2

Martin Drab
Martin Drab

Reputation: 697

The process handle is returned when you call _spawnv in asynchronous mode. I assume the handle is always valid since you can attempt to wait for the spawned process via _cwait (which closes the given handle if it is not a pseudo handle identifying the calling process or thread).

When a process terminates, its kernel objects exists until all handle and pointer references to it are removed. In that state, the process actually does not have an address space and is AFAIK not listed in the list of running processes (you can't see it in the Task Manager).

Upvotes: 1

Related Questions