jds
jds

Reputation: 8279

In C, how can I *simulate* changing the working directory of my parent process?

It looks like I cannot change the working directory of the parent process, but is there any way to simulate this? I am learning C by writing a command-line tool x that allows the user to navigate the filesystem with custom commands. Would it be possible to write something like x enter [directory] and then x look and get something equivalent to cd [directory] and then ls?

My only thought is reading/writing to some .config file before/after every command, a way of managing state across multiple x executions.

I realize this is a problem of my own making, but I've had a lot of fun playing with C and don't want to give up on my idea for a tool that wraps the basic filesystem traversal of the Unix builtins.

Upvotes: 0

Views: 104

Answers (1)

Joshua
Joshua

Reputation: 43327

I worked on a design for something like this years ago (I called it mouse for some reason). The first time it is started, it spawns a background process that reads from a fifo. All further commands get passed in via the fifo and executed from the background process.

There was some difficulty with keeping the fifo open. tail -f on a regular file might be easier. These days, I'd design it with some kind of socket but that's a whole 'notehr can of worms.

Upvotes: 1

Related Questions