What is the difference between a Process' pid, ppid, uid, euid, gid and egid?
In order:
pid
: The is the process ID (PID) of the process you call theProcess.pid
method in.ppid
: The PID of the parent process (the process that spawned the current one). For example, if you runruby test.rb
in a bash shell, PPID in that process would be the PID of Bash.uid
: The UNIX ID of the user the process is running under.euid
: The effective user ID that the process is running under. The EUID determines what a program is allowed to do, based on what the user with this UID is allowed to do. Typically the same asuid
, but can be different with commands likesudo
.gid
: The UNIX group ID the program is running under.egid
: Likeeuid
, but for groups.
Can I get a different UID than EUID and GID than EGID in a command?
You've not set the SUID and SGID bits in the permissions:
sudo chmod ug+s filename
Or, doing the permissions setting all in one, you can use either of these:
sudo chmod 6755 filename # Numeric permissions (octal)
sudo chmod a=rx,u+w,ug+s filename # Symbolic permissions
You should run ls -l filename
after you've finished the permissions setting. With the SUID and SGID bits set, you should see something like:
-rwsr-sr-x 1 2000 2000 8712 May 8 00:18 filename
where the two s
values are crucial in the permissions. You might have names where I get to see the UID and GID numbers.
Meaning of PID, PPID and TGID
- PID: Process Id
- PPID: Parent Process Id (the one which launched this PID)
- TGID: Thread Group Id
see this question for more details
Is there a system call for obtaining the uid/gid of a running process?
At the moment, the only viable solution I can come up with is something along the lines of this. Obviously, not gone to the effort to see if this actually works as I would expect it to yet...:
int len, pid, n, fd = open("/proc/12345/status", O_RDONLY | O_NOATIME);
char buf[4096], whitespace[50];
if (0 < (len = read(fd, buf, 4096)))
{
n = sscanf(buf, "Uid:%s%d ", whitespace, &pid);
}
When the column values for UID and GID fields in /proc/pid/status file will differ
Taking this as a question:
So, in any chance those four columns will show different UIDs.
Yes. Subject to various limitations, processes can change their effective and saved UIDs and GIDs. This is what the setuid()
, setgid()
, seteuid()
, and setegid()
functions do.
The filesystem uid and gid are Linux-specific features that are used mainly, if not entirely, in the context of NFS (see filesystem uid and gid in linux). These can be manipulated with setfsuid()
and setfsgid()
, subject, again, to limitations.
For most processes, all the UIDs will the same and all the GIDs will be the same, but it is conceivable that they would all be different. It is a function of the behavior of the process.
How to get PID of current rake task?
You get the current PID in Ruby with Process.pid
Related Topics
How to Make Sign Up Page Be Root Page in Devise
Rails Scope Find with Current User
Rails 4.2 - Sidekiq Not Sending Emails in Development
How to Use Active Record Without Rails
What Are the Uppercase and Lowercase Rules of Ruby Method Name
Bundle Install: Error: Failed to Build Gem Native Extension. Nio4R Gem
Rails: Creating a Custom Data Type/Creating a Shorthand
Rails Plugin for API Key + Secret Key Signing
How to Install Rvm Without Root Access
How to Apply a Patch to Ruby on Rails
How to Pass Arguments from the Parent Task to the Child Task in Rake
Using Polymorphic Paths with Nested Associations
Configuring Jekyll for Github Project Pages
Error About Nokogiri While Capistrano Deployment on Ubuntu Server
How to Use Ruby Minitest::Spec with Rails for API Integration Tests