Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Getting Next Available Userid

by nardo (Friar)
on Sep 19, 2001 at 19:09 UTC ( #113360=note: print w/replies, xml ) Need Help??

in reply to Getting Next Available Userid

You can use getpwent to get all of the uid's from /etc/passwd then find a free one, or alternately you could run through uid's with getpwuid until you find a free one. Both of these suffer from the fact that a free uid is not necessarily free once you have found it (since another process could have added it right after you found it was free). I assume that programs like useradd will lock the /etc/passwd to prevent this situation, but they may use fcntl for file locking as it is more portable than flock (you can build perl to emulate flock with fcntl(2), but by default it will use flock(2) if available). For groups it would be the same, with getgrent and getgrgid.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-05-25 04:12 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (84 votes). Check out past polls.