- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这是我正在尝试做的事情:
Write a C program using two processes (one parent, one child). Child process goes through entire directory and sends the path of dir along with its size to the parent and the parent prints out the info like this "dir size \tdirpath".
这是我目前所拥有的:
#define _XOPEN_SOURCE 500
#include <ftw.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/wait.h>
static int dirSize = 0;
char *dirPath = NULL;
static int dirInfo(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf){
dirSize = sb -> st_size;
dirPath = fpath;
return 0;
}
int main(int argc, char *argv[]){
pid_t processCheck[1];
int i = 0;
int pipes[1][2];
char *directoryPath = argv[1];
processCheck[1] = fork();
if(processCheck[1]==0){
close(pipes[i][0]);
nftw(directoryPath, dirInfo, 10, FTW_PHYS);
write(pipes[i][1], &dirSize, sizeof dirSize);
write(pipes[i][1], &dirPath, sizeof dirPath);
close(pipes[i][1]);
exit(0);
}
close(pipes[i][1]);
int childProcessStatus;
if(WIFEXITED(childProcessStatus)&&WEXITSTATUS(childProcessStatus)==0){
int v;
char * d;
if(read(pipes[i][0], &v, sizeof v) == sizeof(v)){
printf("%d\t" , v);
}
if(read(pipes[i][0], &d, sizeof d) == sizeof(d)){
printf("%s\n", d);
}
}
close(pipes[i][0]);
return 0;
}
问题:程序正在编译和运行,但没有打印任何内容。我还需要在父进程中与子进程同时使用 HashMap 、链表或树按目录大小对目录进行排序
最佳答案
最明显的错误是您没有创建管道。您需要在 fork
上方添加此行:
pipe(pipes[i]);
另一个错误(或者至少 Undefined Behaviour 在大多数情况下是同一件事)是 processCheck
是一个长度为 1 的数组,这意味着当您尝试访问 processCheck[1]
你已经结束了。
关于c - 使用 ftw 和 process 打印目录大小及其路径名的打印问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49177670/
我想了解是什么让 ClearCase 创建这样的路径(不止一个@@):\TUNE\Integration\XmlFiles\PM_Content@@\main\integ_mp1601\4\Commu
我正在构建我的第一个多语言应用程序。通过 Middelware 成功检测到语言并将其附加到 req.lang。下一步,有没有办法也本地化路由路径?这对于 SEO 非常有用。 这里通常的方法是什么? c
如果选择了一个路径,我想向菜单点添加一个类。 如果每个网站都有自己的 .php/.html 文件,那就很容易了,但是一切都在 一个 中规则 .php 文件,所有内容都通过操作进行导航(?action=
我在 Windows 7(最新的 MSMQ 版本)上将 MSMQ.MSMQQueueInfo 与 jscript 一起使用。这是在加入域的计算机上运行的。由于某种我不知道的原因,它只是不接受我给它的
我有很多带空格的文件夹名称,例如“red dog” --> “c:\red dog\” files = dir str = ['cd ', files(3).name] eval(str) 执行返回错
我正在寻找有关如何使用 getopts 显示不带基名的目录名的信息。这应该首先为我计算机中的所有 sh 文件提供基本名称、制表符,然后是所有目录。 例如,如果我这样做:myBashfile.sh -e
我正在尝试自定义由 devise gem 创建的 url: devise_for :users, path: '', path_names: { sign_in: 'login', s
我有以下网址: https://www.example.com/article/f/1/test+article 我需要通过 JavaScript(纯 JavaScript)从 url 中获取“1”部
我们在我们的应用程序中使用了 boost::filesystem。我有一个“完整”路径,它是通过将多个路径连接在一起构建的: #include #include namespace b
Pathname 的 .children 方法返回的文件系统实体的顺序似乎是任意的,或者至少不是按字母顺序排列的。 有没有办法让这些通过文件系统按字母顺序返回,而不是在返回的数组上调用 .sort?
我正在尝试使用 pip 为 python 3 安装 Gelatin,我得到了这个回溯: Traceback (most recent call last): File "", line 1, in
我有一个注册页面的表格。该表单包含一个图像,该图像会根据情况更改其 src。在提交表单时激活的脚本中,如果该图像具有特定的 src,我希望表单调用警报,因此我需要一种检索和比较值的方法。 HTML:
Ruby 的 Dir、File 和 Pathname 类之间有什么区别?它们似乎共享通用方法,如 basename、dirname、glob 和 join。什么时候使用一种比另一种更有优势? 在将其功
我们在我们的应用程序中使用了 boost::filesystem。我有一个“完整”路径,它是通过将多个路径连接在一起构建的: #include #include namespace b
对于以下代码,我不断收到Uncaught TypeError: undefined is not a function: var jay = /^(\/gallery\/P[\w\dåäö\/]+)$
我正在报告从 native 系统 API 收集的一些信息。 (我知道这很糟糕......但我得到了我无法通过其他方式获得的信息,而且如果/当那个时间到来时,我不必更新我的应用程序。) native A
我需要从 Ruby (1.9.3) 中的 DOS (Win32) 路径获取文件的 NT( native )路径。 意思是,我有字符串: dos_path = "C:\Windows\regedit.e
我才刚刚开始使用 ASP.NET MVC,我有一个有点微不足道的问题:似乎每个 Controller 都有一个附加的类似文件夹的路径,所以我的站点变成了 mydomain.net/Home/somet
下面是bunyan logger的__init__函数。 def __init__(self, *args, **kwargs): """Defined default log format
总结 我如何在 C++ 中使用 libarchive 编写一个 zip 文件,这样路径名称将被 UTF-8 编码?使用 UTF-8 路径名时,特殊字符将在使用 OS X/Linux/Windows 8
我是一名优秀的程序员,十分优秀!