#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<pwd.h>
int main()
{

    struct stat *info;

    int i;
    char *path;
    path=(char *)malloc(200);
    printf(“\nEnter the path of the file whose information is to be found: “);
    scanf(“%s”,path);
    i=stat(path,info);

    if(i==-1)
    {
        printf(“\nstat failed\n\n\n\n”);
        exit(0);
    }

    printf(“\nSize of the file:%d Bytes”,info->st_size);
    printf(“\nOwner Id of the file:%d “,info->st_uid);
    printf(“\nGroup Id of the file owner:%d “,info->st_gid);

    printf(“\nInode NO:%d\n\n\n\n “,info->st_ino);
    return 0;
}

#include<stdio.h>
#include<stdio.h>
int add(int ,int ,int *);
int main()
{
    int *a,n,i,sum,mid;
    printf(“\NEnter the no.of.elements: “);
    scanf(“%d”,&n);
    a=(int *)malloc(n*sizeof(int));
    for(i=0;i<n;i++)
     scanf(“%d”,a+i);
    sum=add(0,n-1,a);
    printf(“\nSum=%d”,sum);
    return 0;

}

int add(int low,int high,int *a)
{
    int mid;
    if(high==low)
     return a[low];
    mid=(low+high)/2;
    return add(low,mid,a)+add(mid+1,high,a);
}

/*DOWNLOAD LINK OF THE FILE:http://www.slideshare.net/hackintoshrao/usrinfogetpwuid*/
/*HACKINTOSH RAO \m/ , codes for GNU/LINUX
  PROGRAM TO GET THE COMPLETE INFORMATION OF THE USER USING “getpwuid” system call in gnu/LINUX
  SYSImageTEM CALLS USED: 1) struct passwd *getpwuid(int uid);
  DESCRIPTION: “getpwuid” system call takes uid of the a user as parameter and then fills in the entries of the built in structure
              ‘passwd’( check out the header pwd.h under /usr/include to get the details of the passwd structure) and returns a
               pointer to it .Using the pointer the members of the structure are accessed to get the user info
                     2)uid_t/int getuid()
  DESCRIPTION:’getuid’ system call returns UID of a user who runs the executable of the code*/
#include<pwd.h> //header for getpwuid system call
#include<unistd.h>//header for getuid system call
#include<stdlib.h>
int main()
{
    struct passwd *usrinfo;
    usrinfo=getpwuid(getuid());
    printf(“\nUser name: %s”,usrinfo->pw_name);
    printf(“\n\nUserID:%d”,usrinfo->pw_uid);
    printf(“\n\nEncrypted password of the user:%s”,usrinfo->pw_passwd);
    printf(“\n\nGroup ID:%d”,usrinfo->pw_gid);
    printf(“\n\nReal name:%s”,usrinfo->pw_gecos);
    printf(“\n\nHOME DIRECTORY OF THE USER:%s”,usrinfo->pw_dir);
    printf(“\n\nDefault login shell:%s\n\n\n\n”,usrinfo->pw_shell);

    return 0;

}

HACKINTOSH EDITOR

This text editor doesnt contain any options like saving the file or other editor ….Its just a simplest one of its kind

/* hackintosh rao \m/ , codes for GNU/LINUX
   Illustration of code which can only be made use
  System calls used:1) uid_t getuid(void);
                    2) char *getlogin(void); */
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
    uid_t uid;/*uid_t is a build in data type, which can hold small numbers*/
    char* username;
    uid=getuid();
    username=getlogin();
    if(uid==1000)//uid of user karthic
    {
        printf(“\nUID is:%d\nWELCOME Username:%s\n\n\n “,uid,username);
        printf(“\nI AM AT YOUR SERVICE\n\n”);
        /*write functionalities here which can only be made use by user with UId 1000*/
        /*not even can root can unlock this,if if root executes the code he cannot make use of it*/

    }
    else
     printf(“\nWrong User, the program is authorized to be used only by %s\n\n”,username);

    return 0;
}
Image

/* hackintosh rao \m/ , codes for GNU/LINUX
   program to print the user ID and username
  System calls used:1) uid_t getuid(void);
                    2) char *getlogin(void); */
#include<stdlib.h>Image
#include<unistd.h>
#include<sys/types.h>
int main()
{
    uid_t uid;/*uid_t is a build in data type, which can hold small numbers*/
    char* username;
    uid=getuid();
    username=getlogin();
    printf(“\nUID is:%d\nUsername:%s\n\n\n “,uid,username);
    return 0;
}

//download link for the file:http://www.slideshare.net/hackintoshrao/countrytimec

/*HACKINTOSH RAO \M/ CODES FOR GNU LINUX
  SYSTEM CALLS USED:1)time_t time(time_t *);
                    2)struct tm *gmtime(time_t *);
  DESCRIPTION:AFTER CALLING “time” system call the returned value of type time_t(%ld) is stored first;
              then the same address of the same value is to be sent to “gmtime” system call;
              gmtime returns a pointer to the built in structure tm;
              then the pointer is used to access the members of the structure which will be filled with
              the information about the time , date ,day , year etc……….
              In this program just fetching the time and year using the pointer to the structure is illustrated
              “gmtime” returns time in GMT and function timeconversion is used to change it to time of a given country*/
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<time.h>
void timeconversion(int *hour,int *min,int diff_hour,int diff_min);
/* timeconversion function is used to convert GMT to time of a given country using the difference from GMT ex:INDIA +5.30 GMT*/
void align(void);
int main()
{
    time_t time_in_sec;/*built in data type to store very large numbers*/
    int hour,min,choice,diff_hour,diff_min;
    struct tm *timestructure;/*built in structure with members which fill the details like day,time and so on*/

  for(;;)
  {
    time_in_sec=time(&time_in_sec);
    timestructure=gmtime(&time_in_sec);
    hour=timestructure->tm_hour;
    min=timestructure->tm_min;
    printf(“\n\t1.GMT\n\t2.Indian Standard Time\n\t3.WASHINGTON D.C(U.S.A)\n\t4.LONDON U.K\n\t5.U.A.E\n\t6.AUSTRALIA\n\t7.EXIT\n”);
    printf(“Enter 1 for GMT or Choose the country: “);
    scanf(“%d”,&choice);
    switch(choice)
    {

        case 2:diff_hour=5;//IST is +5.30 hours ahead of GMT
               diff_min=30;
               timeconversion(&hour,&min,diff_hour,diff_min);

               align();
               printf(“Indian standard Time: %02d:%02d:%02d “,hour,min,timestructure->tm_sec);
               align();
               break ;
        case 1:align();
                printf(“GMT: %02d:%02d:%02d “,timestructure->tm_hour,timestructure->tm_min,timestructure->tm_sec);
                align();
                break;
        case 3:diff_hour=-5;//time in USA is +5.30 hours ahead of GMT
               diff_min=0;
               timeconversion(&hour,&min,diff_hour,diff_min);

               align();
               printf(“WASHINGTON D.C U.S.A: %02d:%02d:%02d “,hour,min,timestructure->tm_sec);
               align();
               break ;
        case 4:diff_hour=0;//IST is +5.30 hours ahead of GMT
               diff_min=0;
               timeconversion(&hour,&min,diff_hour,diff_min);

               align();
               printf(“UK: %02d:%02d:%02d “,hour,min,timestructure->tm_sec);
               align();
               break ;
        case 5:diff_hour=4;//IST is +5.30 hours ahead of GMT
               diff_min=0;
               timeconversion(&hour,&min,diff_hour,diff_min);

               align();
               printf(“UAE: %02d:%02d:%02d “,hour,min,timestructure->tm_sec);
               align();
               break ;
        case 6:diff_hour=11;//IST is +5.30 hours ahead of GMT
               diff_min=0;
               timeconversion(&hour,&min,diff_hour,diff_min);

               align();
               printf(“MELBOURNE,AUSTRALIA: %02d:%02d:%02d “,hour,min,timestructure->tm_sec);
               align();
               break ;
        case 7:exit(0);

        default:align();
                printf(“SELECT THE WRIGHT OPTION”);
                align();

    }
  }
}
void timeconversion(int *hour,int *min,int diff_hour,int diff_min)
{

               *hour=(*hour+diff_hour)%24;/*so a simple math to convert GMT to time of a given country*/
               *min=*min+diff_min;
               if((*min)>=60)
              {
                    *hour=(*hour+1)%24;
                    *min=*min-60;

              }

}
void align()//function just to get the alignments right
{
    printf(“\n\n*************************************************************************\n\n”);
}
Image

//download link for the file:http://www.slideshare.net/hackintoshrao/timesleep
/* HACKINTOSHRAO , CODES FOR GNU/LINUX \m/
   simple illustration of time and difftime system call in GNU/LINUX
   system calls used: 1)time_t time(time *) ;go to /usr/include and use “grep time_t *”
                      2)double difftime(time2,time1);go to /usr/include and use “grep -l difftime *”
                      3)void sleep(int sec);
                      */

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

int main()
{
    time_t time_1970,time2_1970;//time_t is a built in data type and is used to store very large numbers
    int i;
    double timedifference;
    for(i=0;i<10;i++)
    {

        time_1970=time((time_t *)0);
        /*time system call takes in a NULL argument and returns no.of.seconds eclapsed since 1970*/

        printf(“\nThe no.of.seconds passed from 1970 is:%ld “,time_1970);
        sleep(3);
        /*sleep system call halts or pauses the execution for no.of.seconds mentioned as arguments to the call*/
        time2_1970=time((time_t *)0);
        timedifference=difftime(time2_1970,time_1970);
        /*difftime is a system call which returns back the time difference in seconds as a double b/w its 1st and 2nd argument of type time_t*/
        printf(“\n\nHey !! The program was paused for %f seconds”,timedifference);

    }
    exit(0);
}
Image

//download link for the file: http://www.slideshare.net/hackintoshrao/time2c-10761496
/* Hackintosh Rao , Codes for GNU/LINUX \m/ */
/*system calls used :sleep(int sec)         */
/*Sleep system call pauses the execution of instructions for specified no.of.seconds*/
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    int i;
    for(i=0;i<10;i++)
      printf(“\n\t\tWithout time delay”);
      sleep(2);
    printf(“\nWait and watch how the execution halts for 2 seconds each time when SLEEP is called”);
    sleep(2);
    printf(“\nLOADING”);
    for(i=0;i<10;i++)
     {
         printf(“\n# “);
         sleep(2) ;/*the argument for sleep system call is an integer duration in sec for which
                      you want the exection of the instructions to be put to pause */

     }
     exit(0);
}

//download link for the file http://www.slideshare.net/hackintoshrao/forkc
/* —————————————————————– */
/* HACKINTOSH RAO :CODES FOR GNU/LINUX \M/                                              */
/*   This program runs two processes, a parent and a child.  Both of */
/* them run the same loop printing some messages.  Note that printf()*/
/* YOU CAN SEE TWO DIFFERENT PROCESS ID’S PRINTED INDICATING THAT EXECTION IS PERFORMED BY TWO DIFFERENT PROCESSES */

/* —————————————————————– */
/*system calls used :1)fork
                     2)getpid
*/
#include  <stdio.h>
#include  <sys/types.h>
#include <unistd.h>     //header for getpid system call ,to verify go to /usr/include and issue this command “grep -l getpid * “

#define   MAX_COUNT  200

void  ChildProcess(void);                /* child process prototype  */
void  ParentProcess(void);               /* parent process prototype */

void  main(void)
{
     pid_t  pid;

     pid = fork();        //fork system call takes no parameters
                   //a New process in created a the instructions to follow will be parallely executed
     if (pid == 0)
          ChildProcess();
     else
          ParentProcess();
     /*In a normal programming scenario ,Depending on the value of pid either the child process or the parent process function is supposed to be called
       but in this case both the functions gets called as parallel execution of statements takes place after the fork call*/
}
//THESE FUNCTIONS CLEARLY ILLUSTRATES THE LINES EXECUTED BY THE PARENT AND THE LINES EXCUTED BY THE CHILD
//you Will probably see different order of exection of child and parent functions .
void  ChildProcess(void)
{
     int   i;

     for (i = 1; i <= MAX_COUNT; i++)
          printf(“   This line is from child, value = %d,with Process id %d:\n\n”, i,getpid());
     printf(“   *** END OF CHILD PRECESS ***\n”);
}

void  ParentProcess(void)
{
     int   i;

     for (i = 1; i <= MAX_COUNT; i++)
          printf(“This line is from parent, value = %d,with process id %d:\n\n”, i,getpid());
     printf(“*** END OF PARENT***\ PROCESS\n”);
}
Image