non-zero getpid and getuid for root

Asked

Viewed 48 times

0

I have the following problem. While executing:

void main(void){
uid_t getuid(void);
gid_t getgid(void);

uid_t user_id;
gid_t group_id;

printf("user_id: %d\n",user_id);
printf("group_id: %d\n",group_id);
exit(0);
}

I have as return:

user_id: 134513819,group_id: -1216946176.

It was not to return

user_id: 0,group_id: 0.

Since the file belongs to root and is running as root.

1 answer

3

You seem to be declaring the functions (and not calling) in the first two lines, and then you are declaring two variables without throwing any value at them, so naturally they will contain random values.

You’d have to do something like

user_id = getuid();

If the compiler claims that the function does not exist, it is because it remains to include

#include <unistd.h>
#include <sys/types.h>

at the beginning of the program (it was not clear if you had put this or not).

  • Solved. It was just assign to user_id=getuid() and done. Thank you and how much libraries were included.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.