如何设置父进程的工作目录? [英] How do I set the working directory of the parent process?
本文介绍了如何设置父进程的工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
U 究竟如何改变bash的工作目录(或一般的父目录)?
PS shell实用程序 chdir 成功地执行完全相同的操作,因此必须采用编程方式来实现该效果。 不要这样做。
FILE * p;
char cmd [32];
p = fopen(/ tmp / gdb_cmds,w);
fprintf(p,call chdir(\.. \)\\\
detach\\\
quit\\\
);
fclose(p);
sprintf(cmd,gdb -p%d -batch -x / tmp / gdb_cmds,getppid());
系统(cmd);
它可能会 工作,但请注意Bash的 pwd
命令被缓存,不会注意。
As the title reveals it, we are writing a Unix-style shell utility U that is supposed to be invoked (in most cases) from bash.
How exactly could U change the working directory of bash (or parent in general)?
P.S. The shell utility chdir succeeds in doing exactly the same, thus there must be a programmatic way of achieving the effect.
解决方案
Don't do this.
FILE *p;
char cmd[32];
p = fopen("/tmp/gdb_cmds", "w");
fprintf(p, "call chdir(\"..\")\ndetach\nquit\n");
fclose(p);
sprintf(cmd, "gdb -p %d -batch -x /tmp/gdb_cmds", getppid());
system(cmd);
It will probably work, though note that Bash's pwd
command is cached and won't notice.
这篇关于如何设置父进程的工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文