Dev Perfects
40 subscribers
9.23K photos
1.26K videos
468 files
13K links
بخوام خیلی خلاصه بگم
این کانال میاد مطالب کانالای خفن تو حوزه تکنولوژی و برنامه نویسی رو جمع میکنه

پست پین رو بخونید
https://t.iss.one/dev_perfects/455


ارتباط:
https://t.iss.one/HidenChat_Bot?start=936082426
Download Telegram
Forwarded from Dev
.
Forwarded from Dev
.
Forwarded from Dev
.
Forwarded from Dev
.
Forwarded from Dev
.
Forwarded from Dev
The archive is complete
Forwarded from Galaxy Ai
Processes and Programs: Environment Variables

Each process has an associated string array known as the environment variable list. Each of its strings is an element in the form of name=value.

Thus, the environment represents a set of name-value pairs that can be used to store arbitrary information.

When a new process is created, it inherits a copy of its parent's environment. This is a simple yet commonly used form of inter-process communication (IPC), where the environment provides a means to transfer information from the parent process to the child.

The transfer of information from the parent process to the child is one-way and one-time. After the child is created, any subsequent instance can change its own environment, and these changes will be invisible from the outside.

Some library functions allow modifying their behavior by setting environment variables. This enables users to control application behavior without changing the code or recompiling it with the appropriate dependencies.

One classic example is the environment variable LDLIBRARYPATH, which we discussed earlier. When a program uses dynamic libraries, the loader searches for them in system directories like lib or /usr/lib. However, with LDLIBRARYPATH, alternative search paths can be specified:

$ LD_LIBRARY_PATH=/usr/local/lib ./myapp


Defining Environment Variables

In most shells, a value can be added to the environment using the export command:

$ SHELL=/bin/bash 
$ export SHELL


In the example above, the first command creates a shell variable that, without explicit export, will not be inherited by the child process. The second call defines a variable for the environment and places it in the process's environment.

In bash and Korn shells, you can use the following syntax:

$ export SHELL=/bin/bash


The commands shown above permanently add a value to the shell environment, after which this environment is inherited by all child processes created by the shell. A variable can be removed at any time using the unset command:

$ unset VARIABLE_NAME


In the Bourne shell and its descendants (bash and Korn), you can use this syntax to add values to the environment of an executing program:

$ NAME=value program


The definition will be added to the environment of only the child process that executes the specified program. The current list of environment variables can be displayed using the printenv command:

$ printenv
LOGNAME=mtk
SHELL=/bin/bash
HOME=/home/mtk
PATH=/usr/local/bin:/usr/bin:/bin:.
TERM=xterm


The list of environment variables for any process can be examined by accessing the Linux-specific "/proc/PID/environ":

$ cd /proc/2953  
$ cat environ
HOME=/home/xodefenderLANG=en_US.UTF-8LOGNAME=xodefender


Accessing Environment from a Program

In a C program, the list of environment variables can be accessed via the global variable environ. Like argv, the environ variable contains a list of pointers to null-terminated strings. The list itself is terminated with a NULL value:

#include <stdio.h>

extern char **environ;

int main(int argc, char *argv[]) {
char **list;
for (list = environ; *list != NULL; list++) {
puts(*list);
}
exit(EXIT_SUCCESS);
}


An alternative method to access the list of environment variables is to declare a third argument for the main() function:

int main(int argc, char *argv[], char *envp[])


Individual values from the process's environment can be retrieved using getenv():

#include <stdlib.h>
char *getenv(const char *name);


@Galaxy_deve _ #Linux
Forwarded from Linuxor ?
برای ساخت یه بازی به چه چیز هایی لازمه؟ این ریپو اومده هرچی لازمه رو یجا جمع آوری که کرده برای شروع خیلی کمکتون میکنه :


https://github.com/Kavex/GameDev-Resources


🐧 @Linuxor