实现mypwd

1 学习pwd命令

2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码

3 实现mypwd

4 测试mypwd


Linux命令学习:pwd命令

该命令用来显示目前所在的工作目录。指令英文原义:print work directory

执行权限    :All User

指令所在路径:/usr/bin/pwd 或 /bin/pwd
命令语法:

pwd [OPTION]...

命令参数:

参数 长参数 描叙
-L --logical(无效) 当目录为连接路径时,显示连接路径
-P --physical(无效) 显示实际物理路径,而非使用连接(link)路径

查看pwd命令的帮助信息

root@DB-Server init.d]# man pwd
PWD(1) User Commands PWD(1) NAME
pwd - print name of current/working directory SYNOPSIS
pwd [OPTION]... DESCRIPTION
Print the full filename of the current working directory. -L, --logical
use PWD from environment, even if it contains symlinks -P, --physical
avoid all symlinks --help display this help and exit --version
output version information and exit NOTE: your shell may have its own version of pwd, which usually supersedes the version described here. Please refer to your shell鈥檚 documentation for details about the
options it supports. AUTHOR
Written by Jim Meyering. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright 2006 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to
the extent permitted by law. SEE ALSO
The full documentation for pwd is maintained as a Texinfo manual. If the info and pwd programs are properly installed at your site, the command info pwd should give you access to the complete manual. pwd 5.97 PWD(1)
(END)

PWD代码如下:

include
include<sys/stat.h>
include
include
include
include<sys/types.h>
void printpath();
char inode_to_name(int);
int getinode(char );
int main()
{
printpath();
putchar('\n');
return ;
}
void printpath()
{
int inode,up_inode;
char str;
inode = getinode(".");
up_inode = getinode("..");
chdir("..");
str = inode_to_name(inode);
if(inode == up_inode) {
// printf("/%s",str);
return;
}
printpath();
printf("/%s",str);
}
int getinode(char str)
{
struct stat st;
if(stat(str,&st) == -1){
perror(str);
exit(-1);
}
return st.st_ino;
}
char inode_to_name(int inode)
{
char str;
DIR dirp;
struct dirent dirt;
if((dirp = opendir(".")) == NULL){
perror(".");
exit(-1);
}
while((dirt = readdir(dirp)) != NULL)
{
if(dirt->d_ino == inode){
str = (char )malloc(strlen(dirt->d_name)sizeof(char));
strcpy(str,dirt->d_name);
return str;
}
}
perror(".");
exit(-1);
}

截图如下:

PWD的编译及调试的更多相关文章

  1. 开发者说 | 使用Visual Studio Code编译、调试Apollo项目

    转载地址:https://mp.weixin.qq.com/s?__biz=MzI1NjkxOTMyNQ==&mid=2247484266&idx=1&sn=d6bcd4842 ...

  2. 剖析并利用Visual Studio Code在Mac上编译、调试c#程序

    0x00 前言 一周多以前的微软的Build大会上,微软发布了一个让很多人眼前一亮的工具,也是本文的主角——Visual Studio Code.很多使用Windows的朋友都很高兴,认为又多了一个很 ...

  3. 转:在VS2010下编译、调试和生成mex文件

    最近帮人调了一个程序,是网上公开的代码,利用matlab与c++混合编程做三维模型关键点检测,发现他们可以用VS2010编译.调试.生成mexw32文件,因此觉得之前在Matlab上利用mex命令真是 ...

  4. Android之源码之模块编译和调试

    Android之源码之模块编译调试 (一) 进行源码模块修改进行编译的调试 1.首先是从git或者svn上拉一套完整的工程下来,然后全编一下,一般这个时间比较长,大概会得2,3个小时左右, 2,编译成 ...

  5. 附录三 嵌入式C程序的编译与调试

    课程回顾 C语言库的特性和发展 C语言库的常用库函数 标准库函数的特色应用 git@github.com:Kevin-Dfg/Data-Structures-and-Algorithm-Analysi ...

  6. 在windows下使用vs2013编译和调试mysql源代码

    1. 准备工作 1)OS:win10 + VS2013 2)mysql 源码(windows版):mysql-5.6.25.zip 3)perl tool:ActivePerl-5.16.3.1604 ...

  7. 剖析并利用Visual Studio Code在Mac上编译、调试c#程序【转】

    0x00 前言 一周多以前的微软的Build大会上,微软发布了一个让很多人眼前一亮的工具,也是本文的主角——Visual Studio Code.很多使用Windows的朋友都很高兴,认为又多了一个很 ...

  8. 开个CS5.4编译编译,调试错误贴

    记录各种编译,调试中遇到问题.

  9. thinkphp学习笔记3—项目编译和调试模式

    原文:thinkphp学习笔记3-项目编译和调试模式 1.项目编译 在章节2.4项目编译中作者讲到使用thinkphp的项目在第一次运行的时候会吧核心需要加载的文件去掉空白和注释合并到一个文件中编译并 ...

随机推荐

  1. Kafka设计解析(六)- Kafka高性能架构之道

    本文从宏观架构层面和微观实现层面分析了Kafka如何实现高性能.包含Kafka如何利用Partition实现并行处理和提供水平扩展能力,如何通过ISR实现可用性和数据一致性的动态平衡,如何使用NIO和 ...

  2. kernel笔记——内核同步与锁

    内核同步 内核同步解决并发带来的问题,多个线程对同一数据进行修改,数据会出现不一致的情况,同步用于保护共享数据等资源. 有两种形式的并发: 同时进行式并发,在不同cpu上执行的进程同时访问共享数据 二 ...

  3. Notepad++设置背景色

    点击菜单“设置”-“语言格式设置” 在语言中,选中Global Styles,在样式栏选 中Default Style,再在右边点击背景色的颜色方块. 在打开的颜色对话框中点击 More Colour ...

  4. jenkins乱码解决问题

    1.jenkins控制台线上乱码解决 系统管理——系统设置,添加编码环境变量 zh.CH.UTF-8 2.java启动后,tomcat日志显示乱码,原因是环境变量没有带过去,因此shell脚本头部需要 ...

  5. Linux Hung Task分析

    关键词:khungtaskd.TASK_UNINTERRUPTIBLE.nvcsw.nivcsw.last_switch_count等等. 经常会遇到内核打印“INFO: task xxx:xxx b ...

  6. python之configparser模块详解--小白博客

    configparse模块 一.ConfigParser简介 ConfigParser 是用来读取配置文件的包.配置文件的格式如下:中括号“[ ]”内包含的为section.section 下面为类似 ...

  7. SQL Server中存储过程的创建命令

    Create Proc 存储过程名称 ( @参数1 参数类型, @参数2 参数类型, ... ... --最后一行参数,别加逗号了,加逗号的意思是表示后面还有参数 ) AS 需要执行的SQL命令 GO ...

  8. JS 优化条件语句的5个技巧

    前言 在使用 JavaScript 的时候,有时我们会处理大量条件语句,这里有5个技巧帮助我们编写更简洁的条件语句. 一.对多个条件使用 Array.includes 例子: function con ...

  9. 菜鸟学习计划浅谈之Linux系统

    人这一生都是在不断地学习,不断地进步中度过的,刚开始学习任何一门知识的时候,我们都习惯性的称自己为菜鸟,觉得自己对这方面的知识欠缺,水平很low,我也是如此.但我擅长总结,对于自己学习的新知识,总结学 ...

  10. 解决Jenkins邮件配置问题

    最近要配置Jenkins邮箱,由于一直报如下错误,又没办法解决,所以想到了另外的办法发邮件. 我采用shell脚本执行python命令的方式来发邮件: #!/bin/bash cd /software ...