使用proc目录创建我自己的pwd命令 [英] Use proc directory to create my own pwd command

查看:99
本文介绍了使用proc目录创建我自己的pwd命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在完成一项任务。我需要实现自己的pwd命令。我研究并发现我可能必须使用/ proc目录来实现它。我不允许使用bash命令或system()函数。请帮忙。



我尝试过:



我创建了两个文件。在单独的文件中,我实现了pwd命令。在主文件中我使用fork和execlp(gcc,gcc,mypwd, - o,pwd)命令来编译单独的文件。然后在主文件中我执行了mypwd可执行文件。我需要帮助来实现mypwd文件。

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.

推荐答案

为什么要创建一个执行 gcc 的程序来创建另一个程序?

只需创建 maypwd 程序并使用 gcc 进行编译和链接。



作业要求您的程序不使用 system()函数( system(3) - Linux手册页 [ ^ ])执行shell内置命令。



所以你必须寻找返回的C标准库函数当前/工作目录的名称: getcwd(3) - Linux手册页 [ ^ ]。
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[^].


这篇关于使用proc目录创建我自己的pwd命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆