Change language

Python | os.setreuid () method

All functions in the os module raise OSError for invalid or unreachable file names and paths or other arguments that are of the correct type but are not accepted by the operating system.

os.setreuid () in Python is used to set the real and effective user IDs of the current process.

Every user on Unix is such an operating system is identified by a different integer, this unique number is called the UserID.  Real UserID represents the account of the owner of the process. It determines which files this process has access to.  The effective user ID is usually the same as the real user ID, but sometimes it is changed to allow an unprivileged user to access files that can only be accessed by the root user.

Note : os.setreuid() is only available on UNIX platforms, and the functionality of this method is usually only available to the superuser. 
Superuser — it is a root user or administrator who has full rights to launch or run any program in the operating system.

Syntax: os.setreuid (ruid, euid)

Parameters:
ruid : An integer value representing new user id for the current process.
euid : An integer value representing new effective user id for the current process.

Return Type: This method does not return any value.

Code: using the os.setreuid () method

# Python program to explain the os.setreuid () method

 
# import of the os module

import os

 

  
# Get the current process
# real user ID
# using the os.getuid () method

ruid = os.getuid ()

 
# Get the current process
# effective user id.
# using the os. geteuid ()

euid = os. geteuid ()

 

 
# Print current process
# real and effective user ID.

print ( "Real user id of the current process:" , ruid)

print ( "Effective user id of the current process:" , euid)

 

  
# Change current process
# real and effective user IDs
# using the os.setreuid () method

ruid = 100

euid = 200

os.setreuid (ruid, euid)

print ( "Real and effective user ids changed " )

  

  
# Get the current process
# real and effective user IDs

ruid = os.getuid ()

euid = os.geteuid ()

 

 
# Print current process
# real and effective user ID.

print ( "Real user id of the current process:" , ruid)

print ( "Effective user id of the current process:" , euid)

Exit :

 Real user id of the current process: 0 Effective user id of the current process: 0 Real and effective user ids changed Real user id of the current process: 100 Effective user id of the current process: 200 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method