How do you set the current directory of a debugged process?

I have an application that is sensitive to the directory it gets invoked from — it loads some files using relative paths.

When I start the program through a debugger, how can I control what the initial current directory will be?

I'd prefer to avoid adding special code to the debugged program to make it call chdir; my instinct is that the debugger should provide some way to specify that externally, since it's inherently an external setting anyway.

The debugger I'm using is TotalView, but I'm open to answers for other Linux debuggers since it could help me find a comparable setting in TV. I can specify environment variables when I invoke the program, so on a lark, I tried setting PWD, but no luck.


With GDB, the initial working directory is the directory you instantiate GDB from. So, just run GDB from whatever you want the working directory to be. Alternatively, while the program is running, you can change the current working directory just by doing:

(gdb) print chdir("new/working/directory")

GDB also had a built-in command for changing the process' working directory from the GDB prompt:

(gdb) cd new/working/directory

I've never used TotalView, but it should have a similar functionality for executing code (with side effects) from within the debugger.

Need Your Help

MongoDB fetch documents with sort by count


I have a document with sub-document which looks something like:

how to use mongodbexport in python or shell script

python mongodb

i want to create a json output from mongodb by mongodbexport

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.