Accessing system variables in Linux from C code

hello everyone.

Here is an easy question.

How do I access (read and write) system variables in linux from a C program?
For example $HOSTNAME.

I've googled... searched this site but to no luck.

Thnx in advance for any help or pointers.

Sincerly Kristoffer Nordstrm

Comments

  • : hello everyone.
    :
    : Here is an easy question.
    :
    : How do I access (read and write) system variables in linux from a C program?
    : For example $HOSTNAME.
    :
    : I've googled... searched this site but to no luck.
    :
    : Thnx in advance for any help or pointers.
    :
    : Sincerly Kristoffer Nordstrm
    :

    Not sure if this is what you want, but in there are a few environment variable functions.. setenv(), getenv(), putenv(), clearenv(), unsetenv(), and there's also "extern char **environ" (declared in , or you can declare it yourself) which lets you access the environment variables as an array of strings in the form of `name=value'.


    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • Thnx a million.

    That was exactly the functions I was looking for.
    Now I will be able to pass some data between my processes.

    At least I hope so... Im just worried how "global" these variables get .... but as I said thats exactly the answer I was looking for.
    Thnx for the speedy reply.

    Sincerly Kristoffer Nordstrm


    : Not sure if this is what you want, but in there are a few
    environment variable functions.. setenv(), getenv(), putenv(),
    clearenv(), unsetenv(), and there's also "extern char **environ" (declared in , or you can declare it yourself) which lets you access the environment variables as an array of strings in the form of `name=value'.
    :
    :
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :

  • Isn't that what pipe() is used for??



    : Thnx a million.
    :
    : That was exactly the functions I was looking for.
    : Now I will be able to pass some data between my processes.
    :
    : At least I hope so... Im just worried how "global" these variables get .... but as I said thats exactly the answer I was looking for.
    : Thnx for the speedy reply.
    :
    : Sincerly Kristoffer Nordstrm
    :
    :
    : : Not sure if this is what you want, but in there are a few
    : environment variable functions.. setenv(), getenv(), putenv(),
    : clearenv(), unsetenv(), and there's also "extern char **environ" (declared in , or you can declare it yourself) which lets you access the environment variables as an array of strings in the form of `name=value'.
    : :
    : :
    : : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    : :
    : :
    :
    :

    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • I believe that pipe() has use in conjunction with fork() which my text tells me creates a duplicate process as the calling process, but with a different process id.

    If you had completely different processes that you wanted to trade information between, I am not sure that you could do it using pipe().



    ;

    : Isn't that what pipe() is used for??
    :
    :
    :
    : : Thnx a million.
    : :
    : : That was exactly the functions I was looking for.
    : : Now I will be able to pass some data between my processes.
    : :
    : : At least I hope so... Im just worried how "global" these variables get .... but as I said thats exactly the answer I was looking for.
    : : Thnx for the speedy reply.
    : :
    : : Sincerly Kristoffer Nordstrm
    : :
    : :
    : : : Not sure if this is what you want, but in there are a few
    : : environment variable functions.. setenv(), getenv(), putenv(),
    : : clearenv(), unsetenv(), and there's also "extern char **environ" (declared in , or you can declare it yourself) which lets you access the environment variables as an array of strings in the form of `name=value'.
    : : :
    : : :
    : : : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    : : :
    : : :
    : :
    : :
    :
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :

  • Yea you're right. Looks like named pipes would work, but there are better ways. http://www.linuxhq.com/guides/LPG/node7.html

    : I believe that pipe() has use in conjunction with fork() which my text tells me creates a duplicate process as the calling process, but with a different process id.
    :
    : If you had completely different processes that you wanted to trade information between, I am not sure that you could do it using pipe().
    :
    :
    :
    : ;
    :
    : : Isn't that what pipe() is used for??
    : :
    : :
    : :
    : : : Thnx a million.
    : : :
    : : : That was exactly the functions I was looking for.
    : : : Now I will be able to pass some data between my processes.
    : : :
    : : : At least I hope so... Im just worried how "global" these variables get .... but as I said thats exactly the answer I was looking for.
    : : : Thnx for the speedy reply.
    : : :
    : : : Sincerly Kristoffer Nordstrm
    : : :
    : : :
    : : : : Not sure if this is what you want, but in there are a few
    : : : environment variable functions.. setenv(), getenv(), putenv(),
    : : : clearenv(), unsetenv(), and there's also "extern char **environ" (declared in , or you can declare it yourself) which lets you access the environment variables as an array of strings in the form of `name=value'.
    : : : :
    : : : :
    : : : : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    : : : :
    : : : :
    : : :
    : : :
    : :
    : : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    : :
    : :
    :
    :

    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • Thnx for the answers to both of you.

    Teh situation I have is two entirely different processes with different memory and everything.
    I will definatly look at the article mentioned previuosly .... another thought is to use /proc for this.

    Anyway thnx for the time and effort.

    Sincerly Kristoffer Nordstrm
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories