T
Tom
Hello,
I've recently started trying to learn C (for the fun of it!). I have
been using Perl and other languages for many years, but they were
always very high level, this is giving me quite a ride. Here is my
situation:
I have the following code:
////////////////////////////////////////////////////////////
#include <linux/kernel.h>
int main()
{
struct sysinfo s;
sysinfo(&s);
printf("Server uptime: %i days.", s.uptime/60/60/24);
return 0;
}
////////////////////////////////////////////////////////////
This works fine and provides the uptime of a server. However, I'm
trying to understand exactly what it is doing. Here is where my
understanding gets fuzzy:
1) Assign "s" as an instance to the sysinfo structure.
2) ???
3) Print and calculate server uptime.
What is "sysinfo(%s);" actually doing? My limited understanding is
that it is running the sysinfo system call against the address of the
"s" variable. So, "s" is a new instance of the sysinfo structure and
then the address of that new instance is processed by the sysinfo
system call?
I'm just trying to get this concept through my thick head. Any
enlightenment would be appreciated! Thanks.
Tom
I've recently started trying to learn C (for the fun of it!). I have
been using Perl and other languages for many years, but they were
always very high level, this is giving me quite a ride. Here is my
situation:
I have the following code:
////////////////////////////////////////////////////////////
#include <linux/kernel.h>
int main()
{
struct sysinfo s;
sysinfo(&s);
printf("Server uptime: %i days.", s.uptime/60/60/24);
return 0;
}
////////////////////////////////////////////////////////////
This works fine and provides the uptime of a server. However, I'm
trying to understand exactly what it is doing. Here is where my
understanding gets fuzzy:
1) Assign "s" as an instance to the sysinfo structure.
2) ???
3) Print and calculate server uptime.
What is "sysinfo(%s);" actually doing? My limited understanding is
that it is running the sysinfo system call against the address of the
"s" variable. So, "s" is a new instance of the sysinfo structure and
then the address of that new instance is processed by the sysinfo
system call?
I'm just trying to get this concept through my thick head. Any
enlightenment would be appreciated! Thanks.
Tom