HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Environment of a process
Operating System - HP-UX
1830619
Members
2627
Online
110015
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 07:58 AM
10-03-2006 07:58 AM
Environment of a process
When a process is launched, a pointer to the environment is passed to it:
int execve(const char *path, char * const argv[], char * const envp[]);
or
extern char **environ;
Given a running process, I would like to know what its environment is.
As a temptative approach, I have developed the following program:
int main(int argc, char* argv[], char* environ[])
{
int i;
printf("environ = 0x%p\n", environ);
for(i=0; environ[i]; i++)
printf("environ[%d] = %s\n", i, environ[i]);
puts("Press any key...");
getchar();
return 0;
}
whose output is:
environ = 0x800003ffbfff07a0
environ[0] = _=./JMR
environ[1] = TMPDIR=/tmp
...
Press any key...
If I get a core of the process with gdb, when it is waiting at the "Press any key" event, then I can later dump the array at 0x800003ffbfff07a0 and (double-)check the environment strings:
(gdb) x /2xw 0x800003ffbfff07a0
0x800003ffbfff07a0: 0x800003ff 0xbfff0006
(gdb) p (char*) 0x800003ffbfff0006
$1 = 0x800003ffbfff0006 "_=./JMR"
So another way of posing the question could be:
given a running process, how can I know the address of its environment pointer?
int execve(const char *path, char * const argv[], char * const envp[]);
or
extern char **environ;
Given a running process, I would like to know what its environment is.
As a temptative approach, I have developed the following program:
int main(int argc, char* argv[], char* environ[])
{
int i;
printf("environ = 0x%p\n", environ);
for(i=0; environ[i]; i++)
printf("environ[%d] = %s\n", i, environ[i]);
puts("Press any key...");
getchar();
return 0;
}
whose output is:
environ = 0x800003ffbfff07a0
environ[0] = _=./JMR
environ[1] = TMPDIR=/tmp
...
Press any key...
If I get a core of the process with gdb, when it is waiting at the "Press any key" event, then I can later dump the array at 0x800003ffbfff07a0 and (double-)check the environment strings:
(gdb) x /2xw 0x800003ffbfff07a0
0x800003ffbfff07a0: 0x800003ff 0xbfff0006
(gdb) p (char*) 0x800003ffbfff0006
$1 = 0x800003ffbfff0006 "_=./JMR"
So another way of posing the question could be:
given a running process, how can I know the address of its environment pointer?
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP