shell-init: error retrieving current directory 解决方案

现象 

在linux程序运行过程中,调用system()时候出现了

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

原因

诱发的原因为:当前所有路径为已经被删除的路径。常见操作为处于当前目录,又另一个操作删除了当前目录。如下所示:

```
let’s try it:
1、Open a terminal window and go cd ~
2、Create a new directory and cd into it mkdir adir && cd adir
3、Now, open a new terminal window and go to that same place cd ~
4、Now, delete the directory rm -rf adir
5、Finally - go back to the previous window and try to do just about any command you can come up with and it will give you errors like the ones above.
Not surprisingly, since you are in essence running the command in a directory that doesn’t exist.
Easy to mix up when you are new to the terminal - and apparently hard to grasp even if you have been using the terminal for years…
```

解决方案

如果觉得没有类似上述的操作,可能的解法包括:

1、查看当前环境变量是否有问题

```

can you check your HOME env variable ? echo $HOME; if that points to an unexisting location, that't it. – Costi Ciudatu Sep 9 '12 at 15:57

```

2、虚拟机设备的硬件虚拟化未开启

```
not after rebooting the problem is still there . But SOLVED
I am running the traccar server in a QEMU virtualization environmentas as a virtual machine , one of the disabled options for this virtual machine was "KVM Hardware Virtualization" . After enabling this option all the error messages completely disappeared and all commands running as expected . this may give you a clue to a code problem. thank you
```
3、再看看代码,把所有调用 system 的相关log打印出来,查看是经过哪个操作后就会出现此error log。

本人就是通过添加log后,发现是调度一个解压函数,解压函数内部进行了移动目录的操作,后续将此解压目录删除后。进程所处于目录还是位于解压目录下,而此时解压目录不存在,于是报出此 error。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值