#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    48
    Rep Power
    2

    What's the difference between sysconf and rlimit?


    I'm trying to determine which to use to check if my process can function correctly. I'm confused why there are limits in limits.h and then in sysconf and then you can query/set them with rlimit. So I want to make sure that I'm using the correct functions to achieve my goal. My process is not SU so I won't ever be setting the hard limit.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,886
    Rep Power
    481
    My process is SU so I cannot help much. I'm just thinking that if you have only one bit to use then you can assign a maximum of 2 states to it. These you can choose to mean anything you like. The "off" state could represent `S' and the "on" state could represent `U'.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    48
    Rep Power
    2
    Originally Posted by b49P23TIvg
    My process is SU so I cannot help much. I'm just thinking that if you have only one bit to use then you can assign a maximum of 2 states to it. These you can choose to mean anything you like. The "off" state could represent `S' and the "on" state could represent `U'.
    Umm, either you were trying to make a joke, or you don't know what Super User (root, admin, etc,) is.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,886
    Rep Power
    481

    sandwich


    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    48
    Rep Power
    2
    Ok, that's a pretty funny web site but it does not answer my question (or explain anything on this thread as far as I can tell.)
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    If I remember correctly, the sysconfig() stuff cannot be changed by a process (i.e.) they are configured at a kernel level and need a recompile of the operating system kernel and/or C libraries to change them. You can only read those values, but not alter them at runtime.

    With setrlimit()/getrlimit(), you can read and change the values (within reason) of certain resources at runtime. For instance, you can call setrlimit() to set the max. core dump size of a process, which is useful if a process crashed often and you don't want to fill your hard disk up with large files.

    The parameters you can read/set with rlimit are different from the parameters that you can read with sysconfig(). They deal with different system knobs.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    48
    Rep Power
    2
    Originally Posted by Scorpions4ever
    If I remember correctly, the sysconfig() stuff cannot be changed by a process (i.e.) they are configured at a kernel level and need a recompile of the operating system kernel and/or C libraries to change them. You can only read those values, but not alter them at runtime.

    With setrlimit()/getrlimit(), you can read and change the values (within reason) of certain resources at runtime. For instance, you can call setrlimit() to set the max. core dump size of a process, which is useful if a process crashed often and you don't want to fill your hard disk up with large files.

    The parameters you can read/set with rlimit are different from the parameters that you can read with sysconfig(). They deal with different system knobs.
    Yes! Now we are cooking.
    So, if I want my process to check if it has the resources at it's disposal for x and y computation should I check sysconf or should I check rlimit (and set the limit to max if the lower limit is to low?)
    Obviously, rlimt max cannot have a value greater then the value returned by sysconf.
    But the question still comes to mind, "Why are there three ways to determine the available resources on a computer (namely, limits.h, sysconf, and rlimit?)"
  14. #8
  15. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Originally Posted by ballsystemlord
    Yes! Now we are cooking.
    So, if I want my process to check if it has the resources at it's disposal for x and y computation should I check sysconf or should I check rlimit (and set the limit to max if the lower limit is to low?)
    First, sysconf() and getrlimit() return the values of different resource settings (without overlap), so you call the appropriate one depending on what information your program seeks.

    Originally Posted by ballsystemlord
    Obviously, rlimt max cannot have a value greater then the value returned by sysconf.
    But the question still comes to mind, "Why are there three ways to determine the available resources on a computer (namely, limits.h, sysconf, and rlimit?)"
    As noted above, sysconf() and getrlimit() return different information about different resources. The stuff that getrlimit() returns can generally be modified at runtime with setrlimit().

    The stuff that sysconf() returns are configured at a system level. You cannot modify those values at runtime. To change them, you need to change some system level include files, then rebuild your operating system kernel (something that isn't done much these days, but was much more common in the late 90s/early 2000s) and reboot your machine to use your new kernel.

    Now for limits.h. Almost everything that is returned by sysconf() is also available from <limits.h> or <unistd.h>. The difference is that the stuff in <limits.h> and <unistd.h> is available at compile time. Therefore, if you write a program like this:
    Code:
    #include <unistd.h>
    char hostname[HOST_NAME_MAX];
    and compile this on your machine, it will size the array hostname based on the value of HOST_NAME_MAX on your machine. Now, if you distribute the binary file to someone else, the size of the array is set to the HOST_NAME_MAX of the machine it was compiled on (i.e. your machine), which may not be the same as the HOST_NAME_MAX value on someone else's machine.

    Now if you did this instead:
    Code:
    #include <unistd.h>
    ...
    int size = sysconf(_SC_HOST_NAME_MAX);
    char *hostname = malloc(size + 1); // Add 1 more for \0.
    then the size of the array will be allocated at runtime and based upon the HOST_NAME_MAX value of whatever machine it is running on.

    Of course, the actual likelihood of someone mucking with the HOST_NAME_MAX value on their machine is pretty low (remember, needs kernel recompile + who knows what other programs need to be recompiled to continue working), but some of the other parameters (e.g. CHILD_MAX, CLOCK TICKS, OPEN_MAX etc.) may be different on systems with custom compiled kernels.

    Hope this helps.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    48
    Rep Power
    2
    Originally Posted by Scorpions4ever
    First, sysconf() and getrlimit() return the values of different resource settings (without overlap), so you call the appropriate one depending on what information your program seeks.
    You are so right. They are close (like RLIMIT_RSS and _SC_AVPHYS_PAGES.)

    Thanks!
    And thanks for the info on limits.h too.

IMN logo majestic logo threadwatch logo seochat tools logo