change environment variable on a running process in mac












0















I have a running process on mac and I want to change is environment variable from out side the process, using some command line utility.



How can I do that?










share|improve this question























  • Which variable do you want to change and why? Do you have access to the source code of the process?

    – Mark Setchell
    Nov 30 '18 at 22:07











  • I want to set SH_AUTH_SOCK and SSH_AGENT_PID variable to a running IntelliJ. I want the run/debug processes will be have that env variables. I know that I can set the env variables of the in the 'edit configuration' before running/debugging the program but the value of these variables is determent by running a script.

    – yoni
    Dec 2 '18 at 10:16











  • A technique I have used in the past is to change a value in a config file, and send the process a SIGHUP which causes it to re-read the config file.

    – Mark Setchell
    Dec 2 '18 at 11:05
















0















I have a running process on mac and I want to change is environment variable from out side the process, using some command line utility.



How can I do that?










share|improve this question























  • Which variable do you want to change and why? Do you have access to the source code of the process?

    – Mark Setchell
    Nov 30 '18 at 22:07











  • I want to set SH_AUTH_SOCK and SSH_AGENT_PID variable to a running IntelliJ. I want the run/debug processes will be have that env variables. I know that I can set the env variables of the in the 'edit configuration' before running/debugging the program but the value of these variables is determent by running a script.

    – yoni
    Dec 2 '18 at 10:16











  • A technique I have used in the past is to change a value in a config file, and send the process a SIGHUP which causes it to re-read the config file.

    – Mark Setchell
    Dec 2 '18 at 11:05














0












0








0








I have a running process on mac and I want to change is environment variable from out side the process, using some command line utility.



How can I do that?










share|improve this question














I have a running process on mac and I want to change is environment variable from out side the process, using some command line utility.



How can I do that?







macos environment-variables






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 9:16









yoniyoni

466




466













  • Which variable do you want to change and why? Do you have access to the source code of the process?

    – Mark Setchell
    Nov 30 '18 at 22:07











  • I want to set SH_AUTH_SOCK and SSH_AGENT_PID variable to a running IntelliJ. I want the run/debug processes will be have that env variables. I know that I can set the env variables of the in the 'edit configuration' before running/debugging the program but the value of these variables is determent by running a script.

    – yoni
    Dec 2 '18 at 10:16











  • A technique I have used in the past is to change a value in a config file, and send the process a SIGHUP which causes it to re-read the config file.

    – Mark Setchell
    Dec 2 '18 at 11:05



















  • Which variable do you want to change and why? Do you have access to the source code of the process?

    – Mark Setchell
    Nov 30 '18 at 22:07











  • I want to set SH_AUTH_SOCK and SSH_AGENT_PID variable to a running IntelliJ. I want the run/debug processes will be have that env variables. I know that I can set the env variables of the in the 'edit configuration' before running/debugging the program but the value of these variables is determent by running a script.

    – yoni
    Dec 2 '18 at 10:16











  • A technique I have used in the past is to change a value in a config file, and send the process a SIGHUP which causes it to re-read the config file.

    – Mark Setchell
    Dec 2 '18 at 11:05

















Which variable do you want to change and why? Do you have access to the source code of the process?

– Mark Setchell
Nov 30 '18 at 22:07





Which variable do you want to change and why? Do you have access to the source code of the process?

– Mark Setchell
Nov 30 '18 at 22:07













I want to set SH_AUTH_SOCK and SSH_AGENT_PID variable to a running IntelliJ. I want the run/debug processes will be have that env variables. I know that I can set the env variables of the in the 'edit configuration' before running/debugging the program but the value of these variables is determent by running a script.

– yoni
Dec 2 '18 at 10:16





I want to set SH_AUTH_SOCK and SSH_AGENT_PID variable to a running IntelliJ. I want the run/debug processes will be have that env variables. I know that I can set the env variables of the in the 'edit configuration' before running/debugging the program but the value of these variables is determent by running a script.

– yoni
Dec 2 '18 at 10:16













A technique I have used in the past is to change a value in a config file, and send the process a SIGHUP which causes it to re-read the config file.

– Mark Setchell
Dec 2 '18 at 11:05





A technique I have used in the past is to change a value in a config file, and send the process a SIGHUP which causes it to re-read the config file.

– Mark Setchell
Dec 2 '18 at 11:05












1 Answer
1






active

oldest

votes


















2














You cannot change the environment variables of a running process via an external utility. Doing so would require the utility to modify the address space of the process. Note that this is not a limitation of macOS. This is a limitation of the UNIX process model. When a UNIX process is created by the kernel the environment variables are put in its address space; typically near the top of the stack. They are not stored in the kernel data structures for the process. And thus there are no system calls for getting or setting those vars. Which means there is no way for one process to affect the env vars of a second process other than at the time the second process is created via execve() or a related syscall.






share|improve this answer
























  • This is generally the correct way to think about it. The exception is, basically, a debugger or something very like a debugger, which can read and write the target's memory and even make the target call a function like setenv().

    – Ken Thomases
    Dec 1 '18 at 0:06











  • @ken-thomases Yes, and I've actually done that; i.e., used ptrace(2) to modify the address space of a running process. But anyone asking this question isn't going to know enough to be able to do that and in any case it isn't in general safe to do so. Consider too that simply changing the TZ or LANG value isn't enough. You'll also need to force the process to call setlocale() or similar function. Which, depending on the current state of the process may not be safe.

    – Kurtis Rader
    Dec 1 '18 at 17:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408679%2fchange-environment-variable-on-a-running-process-in-mac%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You cannot change the environment variables of a running process via an external utility. Doing so would require the utility to modify the address space of the process. Note that this is not a limitation of macOS. This is a limitation of the UNIX process model. When a UNIX process is created by the kernel the environment variables are put in its address space; typically near the top of the stack. They are not stored in the kernel data structures for the process. And thus there are no system calls for getting or setting those vars. Which means there is no way for one process to affect the env vars of a second process other than at the time the second process is created via execve() or a related syscall.






share|improve this answer
























  • This is generally the correct way to think about it. The exception is, basically, a debugger or something very like a debugger, which can read and write the target's memory and even make the target call a function like setenv().

    – Ken Thomases
    Dec 1 '18 at 0:06











  • @ken-thomases Yes, and I've actually done that; i.e., used ptrace(2) to modify the address space of a running process. But anyone asking this question isn't going to know enough to be able to do that and in any case it isn't in general safe to do so. Consider too that simply changing the TZ or LANG value isn't enough. You'll also need to force the process to call setlocale() or similar function. Which, depending on the current state of the process may not be safe.

    – Kurtis Rader
    Dec 1 '18 at 17:33
















2














You cannot change the environment variables of a running process via an external utility. Doing so would require the utility to modify the address space of the process. Note that this is not a limitation of macOS. This is a limitation of the UNIX process model. When a UNIX process is created by the kernel the environment variables are put in its address space; typically near the top of the stack. They are not stored in the kernel data structures for the process. And thus there are no system calls for getting or setting those vars. Which means there is no way for one process to affect the env vars of a second process other than at the time the second process is created via execve() or a related syscall.






share|improve this answer
























  • This is generally the correct way to think about it. The exception is, basically, a debugger or something very like a debugger, which can read and write the target's memory and even make the target call a function like setenv().

    – Ken Thomases
    Dec 1 '18 at 0:06











  • @ken-thomases Yes, and I've actually done that; i.e., used ptrace(2) to modify the address space of a running process. But anyone asking this question isn't going to know enough to be able to do that and in any case it isn't in general safe to do so. Consider too that simply changing the TZ or LANG value isn't enough. You'll also need to force the process to call setlocale() or similar function. Which, depending on the current state of the process may not be safe.

    – Kurtis Rader
    Dec 1 '18 at 17:33














2












2








2







You cannot change the environment variables of a running process via an external utility. Doing so would require the utility to modify the address space of the process. Note that this is not a limitation of macOS. This is a limitation of the UNIX process model. When a UNIX process is created by the kernel the environment variables are put in its address space; typically near the top of the stack. They are not stored in the kernel data structures for the process. And thus there are no system calls for getting or setting those vars. Which means there is no way for one process to affect the env vars of a second process other than at the time the second process is created via execve() or a related syscall.






share|improve this answer













You cannot change the environment variables of a running process via an external utility. Doing so would require the utility to modify the address space of the process. Note that this is not a limitation of macOS. This is a limitation of the UNIX process model. When a UNIX process is created by the kernel the environment variables are put in its address space; typically near the top of the stack. They are not stored in the kernel data structures for the process. And thus there are no system calls for getting or setting those vars. Which means there is no way for one process to affect the env vars of a second process other than at the time the second process is created via execve() or a related syscall.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 30 '18 at 21:37









Kurtis RaderKurtis Rader

3,309610




3,309610













  • This is generally the correct way to think about it. The exception is, basically, a debugger or something very like a debugger, which can read and write the target's memory and even make the target call a function like setenv().

    – Ken Thomases
    Dec 1 '18 at 0:06











  • @ken-thomases Yes, and I've actually done that; i.e., used ptrace(2) to modify the address space of a running process. But anyone asking this question isn't going to know enough to be able to do that and in any case it isn't in general safe to do so. Consider too that simply changing the TZ or LANG value isn't enough. You'll also need to force the process to call setlocale() or similar function. Which, depending on the current state of the process may not be safe.

    – Kurtis Rader
    Dec 1 '18 at 17:33



















  • This is generally the correct way to think about it. The exception is, basically, a debugger or something very like a debugger, which can read and write the target's memory and even make the target call a function like setenv().

    – Ken Thomases
    Dec 1 '18 at 0:06











  • @ken-thomases Yes, and I've actually done that; i.e., used ptrace(2) to modify the address space of a running process. But anyone asking this question isn't going to know enough to be able to do that and in any case it isn't in general safe to do so. Consider too that simply changing the TZ or LANG value isn't enough. You'll also need to force the process to call setlocale() or similar function. Which, depending on the current state of the process may not be safe.

    – Kurtis Rader
    Dec 1 '18 at 17:33

















This is generally the correct way to think about it. The exception is, basically, a debugger or something very like a debugger, which can read and write the target's memory and even make the target call a function like setenv().

– Ken Thomases
Dec 1 '18 at 0:06





This is generally the correct way to think about it. The exception is, basically, a debugger or something very like a debugger, which can read and write the target's memory and even make the target call a function like setenv().

– Ken Thomases
Dec 1 '18 at 0:06













@ken-thomases Yes, and I've actually done that; i.e., used ptrace(2) to modify the address space of a running process. But anyone asking this question isn't going to know enough to be able to do that and in any case it isn't in general safe to do so. Consider too that simply changing the TZ or LANG value isn't enough. You'll also need to force the process to call setlocale() or similar function. Which, depending on the current state of the process may not be safe.

– Kurtis Rader
Dec 1 '18 at 17:33





@ken-thomases Yes, and I've actually done that; i.e., used ptrace(2) to modify the address space of a running process. But anyone asking this question isn't going to know enough to be able to do that and in any case it isn't in general safe to do so. Consider too that simply changing the TZ or LANG value isn't enough. You'll also need to force the process to call setlocale() or similar function. Which, depending on the current state of the process may not be safe.

– Kurtis Rader
Dec 1 '18 at 17:33




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408679%2fchange-environment-variable-on-a-running-process-in-mac%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word