Sharing File Handle between two different proceses

Suppose there are two processes p1 and p2 , p1 opens a handle to a file and shares this handle to p2 through shared memory, will the p2 able to use it?

No, the second process cannot use the handle. Handles are process specific.

1 Like

and shares this handle to p2 through shared memory,

Of course, Mr. Burn is correct… for the most commonly understood general meaning of your phrase.

I just wanted to point out that if by “shares this handle to P2” you mean “take the value of the handle as returned to P1 from the file open operation”… then see Mr. Burn’s answer.

If you mean anything else, like if hiding in your question about a specific implementation technique there lives a question such as “Can P1 having opened a handle to a file, share that handle to another process so that the target process, P2, does not have to open the file”… the answer is “Yes, absolutely.” In this case, see the docs for DuplicateHandle. You could, of course, have P1 create P2 and cause P2 to inherit P1’s handles. For this see the docs for Inheritance.

Peter

1 Like