JetCracker

Life-time learner's blog

Tag Archives: shell

[Unix C] ID implementation

Hello.

Last time I posted my implementation of linux command echo. Now I’d like to introduce my implementation of id (which was another task from my IT teacher). This unix-shell command is rather simple and its task is to print real and effective user and group IDs.

Firstly, let’s see how to obtain current user’s ID and group ID. Take a look at the folowing code:

#include <stdio.h>
#include <unistd.h>

int uid, gid;

int main(){
    uid = getuid();
    gid = getgid();
    printf("UID: %d; GID: %d\n", uid, gid);
    return 0;
}

But functionality of ID command in Linux is way more complex! It took me almost 3 hours to implement all it’s features. Read more of this post