Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on an assignment. I need to implement my own pwd command. I researched and found that I may have to use /proc directory to implement this.I am not allowed to use bash commands or system() function. Please help.

What I have tried:

I have created two files. In the separate file I have implemented the pwd command. In the main file I have used fork and execlp("gcc","gcc","mypwd","-o","pwd") command to compile the separate file.And then in the main file I have executed the mypwd executable. I need help in implementing the mypwd file.
Posted
Updated 30-Jul-16 22:10pm

1 solution

Why do you create a program that executes gcc to create another program?
Just create your maypwd program and compile and link it using gcc.

The assignment requires that your program did not use the system() function (system(3) - Linux manual page[^]) to execute a shell built-in command.

So you have to look for C standard library function that returns the name of the current / working directory: getcwd(3) - Linux manual page[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900