Difference between EUID and UID?
EUID is not the same as UID. At what context are these both are used in the script? I tried to get the values by echo «UID is $UID and EUID is $EUID» , but only space came as output. My machine runs Ubuntu 12.04 LTS. Seen at some sites that this is usually used to check whether it is root user and all but not able to get proper difference.
A link to know how to change uid and gid. usermod -u groupmod -g find / -user -exec chown -h <> \; find / -group -exec chgrp -h <> \; usermod -g
2 Answers 2
They’re different when a program is running set-uid. Effective UID is the user you changed to, UID is the original user.
When I am running inside a script it is not coming, but when i write it directly on the shell it is working!
UID is the ID of the user that executed the program.
EUID (Effective UID) is the user ID the process is executing. Usually both are equal, unless using a program with SetUID to for example increase your privileges. A common case where UID and EUID are different would be executing sudo.
EUID and UID variables only work on bash, not in dash (in Debian based distros as Ubuntu sh is usually a symlink to dash).
If you are running the script interactively you might not have bash configured as your default shell, run bash before trying.
If you are running it from console:
If you are running it using its path (for example ./script.sh ) ensure the first line of the script is:
In that post the command id is mentioned, where:
id -u # is the EUID id -u -r # is the UID
What do the identifiers PID, PPID, SID, PGID, UID, EUID mean?
unix.stackexchange.com/questions/82724 has names for PGID and SID, if that’s what you’re looking for.
Two possibilities: your teacher wants you to print environment variables variables or your teacher wants you to use UNIX APIs to get the values that the system put into those variables. E.g. PPID is parent’s process PID. Try echo $PPID to see it in your environment.
1 Answer 1
- PID — Process ID
- PPID — Parent Process ID
- SID — Session ID
- PGID — Process Group ID
- UID — User ID
- EUID — Effective User ID
Take a look at this SO Post and the first answer for a healthy explanation of what they’re for.
3.270 Parent Process ID
An attribute of a new process identifying the parent of the process. The parent process ID of a process is the process ID of its creator, for the lifetime of the creator. After the creator’s lifetime has ended, the parent process ID is the process ID of an implementation-defined system process.
3.343 Session
A collection of process groups established for job control purposes. Each process group is a member of a session. A process is considered to be a member of the session of which its process group is a member. A newly created process joins the session of its creator. A process can alter its session membership; see setsid(). There can be multiple process groups in the same session.
3.296 Process Group
A collection of processes that permits the signaling of related processes. Each process in the system is a member of a process group that is identified by a process group ID. A newly created process joins the process group of its creator.
3.297 Process Group ID
The unique positive integer identifier representing a process group during its lifetime.
3.142 Effective User ID †
An attribute of a process that is used in determining various permissions, including file access permissions; see also User ID.
† Note that the EUID and EGID (Effect Group ID) are not used for filesystem permissions under Linux which takes filesystem’s FSUID and FSGID fields respectively instead.