Better way to use a command,whether to give absolute path or just command.
For example: Is it better to use /usr/bin/ls or ls
1)Using absolute path is advisable for "root" userid because that will provide:
security :using a full path adds security, then your system is insecure to begin with. Using a full path will do little if anything to improve it.
2)if somebody creates dummy "ls" command in your home directory and you add
your home > in PATH, then when you enter "ls" , "dummy ls" will be executed
anyways in some cases it is necessary to use absolute paths. For example, cron table entries require full paths to the commands because the cron daemon doesn't maintain a PATH variable.
Wednesday, January 7, 2009
Thursday, January 1, 2009
Time Structure (struct tm) with an example
Time structure
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
}
Description of each element is :
tm_sec seconds after the minute 0-61
tm_min minutes after the hour 0-59
tm_hour hours since midnight 0-23
tm_mday day of the month 0-31
tm_mon month since january 0-11
tm_year years since 1900
tm_wday weekday(days since sunday) 0-6
tm_yday yearday(days since Jan10 0-365
tm_isdst daylight saving time flag
The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
* tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems
Example:
/* time example */
#include <stdio.h>
#include <time.h>
#include <conio.h>
int main ()
{
time_t rawtime;
rawtime = time (NULL);
printf ("current time is :%s", ctime(&rawtime));
struct tm *mytime;
mytime = localtime(&rawtime);
printf ("current time is :%s",asctime(mytime));
printf("%d %d %d %d %d %d %d %d %d",mytime->tm_year,mytime->tm_mon ,mytime->tm_yday,mytime->tm_mday, \
mytime->tm_mday ,mytime->tm_hour , \
mytime->tm_min , \
mytime->tm_sec , \
mytime->tm_isdst);
getch();
return 0;
}
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
}
Description of each element is :
tm_sec seconds after the minute 0-61
tm_min minutes after the hour 0-59
tm_hour hours since midnight 0-23
tm_mday day of the month 0-31
tm_mon month since january 0-11
tm_year years since 1900
tm_wday weekday(days since sunday) 0-6
tm_yday yearday(days since Jan10 0-365
tm_isdst daylight saving time flag
The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
* tm_sec is generally 0-59. Extra range to accommodate for leap seconds in certain systems
Example:
/* time example */
#include <stdio.h>
#include <time.h>
#include <conio.h>
int main ()
{
time_t rawtime;
rawtime = time (NULL);
printf ("current time is :%s", ctime(&rawtime));
struct tm *mytime;
mytime = localtime(&rawtime);
printf ("current time is :%s",asctime(mytime));
printf("%d %d %d %d %d %d %d %d %d",mytime->tm_year,mytime->tm_mon ,mytime->tm_yday,mytime->tm_mday, \
mytime->tm_mday ,mytime->tm_hour , \
mytime->tm_min , \
mytime->tm_sec , \
mytime->tm_isdst);
getch();
return 0;
}
Subscribe to:
Posts (Atom)
