Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Change UID for threads?

by MarkM (Curate)
on Jul 09, 2003 at 01:55 UTC ( [id://272535]=note: print w/replies, xml ) Need Help??


in reply to Change UID for threads?

I suspect you are executing under Linux, and therefore, I do not find the behaviour you are observing to be surprising.

Linux has (until recently) implemented threads as separate processes that share the same file descriptors and memory (among a few other things). This behaviour conflicts with the behaviour for threads defined by POSIX.

More recent thread libraries for Linux, including NPTL honour the POSIX specification much more closely. More recent patches to Linux (some of which are only in the 2.5 stream) modify Linux to work similar to other operating systems (and compatible with POSIX).

In summary, I suggest that you do not rely on this behaviour, unless you wish to enforce that all of the users of your code remain at the version of Linux and GLIBC that you are currently using to perform your tests.

Cheers,
mark

Replies are listed 'Best First'.
Re: Re: Change UID for threads?
by mbalex (Beadle) on Jul 09, 2003 at 04:00 UTC
    Thank you for your explanation. Since threads are still at "dev"-status (and btw slow on creation in perl), I'll switch to forking processes. Those hopefully work the same on different kernels/implementations. Do they?

    You mentioned that memory is beeing shared when using threads. I could sucessfully change shared memory data as a non-superuser (with this threads-behaviour). But if you now use IPC::Shareable, you are able to set permissions for the shared memory between processes. Is the sharing between processes or threads on the same level (on Linux)? So you possibly could change permissions for thread shared memory as well? I'm just curious about shared memory, because it seems to me to be a good IPC tool.

      Threads share memory by using the same virtual memory space. Memory at address 0xDD000000 in one thread is the same memory at address 0xDD000000 in the other thread. If malloc() is executed in one thread, the address can be passed to the other thread, and the other thread can access it as expected.

      IPC shared memory segments are a little different. The memory is registered against an identifier, and exists outside of the address space of the other processes. Processes that use the shm*() controls can map the shared memory segment into their virtual memory. IPC shared memory segments are protected, as you say, with user and group permissions.

      As for which one to use? This is a hard call. It becomes even harder when you bring Perl into the picture, as Perl threads does not allow you to take full advantage of the fact that memory is shared (memory has to be copied from one thread to another, as opposed to accessed in a synchronized manner). Given that you want to use permissions, and have each execution thread running as a different userid, IPC::Shareable may be your only real option.

      Good luck!
      mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://272535]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-18 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found