Global variables are used extensively to pass information between sections of code that do not share a caller/callee relation like concurrent threads and signal handlers.
Without proper locking (such as with a mutex), code using global variables will not be thread-safe except for read only values in protected memory.
Child processes therefore cannot use environment variables to communicate with their peers, avoiding the action at a distance problem.
A number of non-structured languages, such as (early versions of) BASIC, COBOL and Fortran I (1956) only provide global variables.
Variables declared with file scope are visible between their declaration and the end of the compilation unit (.c file) (unless shadowed by a like-named object in a nearer scope, such as a local variable); and they implicitly have external linkage and are thus visible to not only the .c file or compilation unit containing their declarations but also to every other compilation unit that is linked to form the complete program.
Where this global access mechanism is judged problematic, it can be disabled using the static keyword which restricts a variable to file scope, and will cause attempts to import it with extern to raise a compilation (or linking) error.
In Java, static fields (also known as class variables) exist independently of any instances of the class and one copy is shared among all instances; hence public static fields are used for many of the same purposes as global variables in other languages because of their similar "sharing" behavior: PHP has a global keyword and a number of unusual ways of using global variables.
A general purpose one is the $GLOBALS superglobal, which contains all the variables defined out of function scope.