Social Icons

Wednesday, 1 May 2013

Machine Information Using Library Function getuid,getgid,gethostname


#include<stdio.h>
#include<sys/types.h>
#include<sys/utsname.h>
#include<unistd.h>
#include<stdlib.h>
#include<pwd.h>
int main()
{
uid_t uid;
gid_t gid;
char s[100];
struct passwd *pw;
struct utsname uts;

uid=getuid();
gid=getgid();

printf("\n userid : %d  , groupid : %d ",uid,gid);
printf("\n login name : %s ",getlogin());

  pw=getpwuid(uid);
printf("\n uid : %d , gid :  %d , name : %s",pw->pw_uid,pw->pw_gid,pw->pw_name);

gethostname(s,255);
printf("\n host name : %s",s);

uname(&uts);

printf("\n machine name :  %s , \n  sysname :  %s ,\n  version : %s ,\n Nodename : %s ,\n  ",uts.machine,uts.sysname,uts.version,uts.nodename);
return 0;
}

No comments:

Post a Comment

 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management