折腾了半天,还是想不通,为什么用execlcall启动的dash就变成僵尸了。
下面是一个最小的测试用例——我只是 fork 一个孩子,复制 std [in,out,err]描述符,然后启动sh。
#include <cstdio>
#include <fcntl.h>
#include <cstring>
#include <stdlib.h>
#include <cerrno>
#include <unistd.h>
int main() {
int pipefd[2];
enum {
STDOUT_TERM = 0,
STDIN_TERM = 1
};
if (pipe(pipefd) == -1) { //make a pipe
perror("pipe");
return 0;
}
pid_t pid = fork();
if (pid == 0)
{// Child
dup2(pipefd[STDIN_TERM], STDIN_FILENO);
dup2(pipefd[STDOUT_TERM], STDOUT_FILENO);
dup2(pipefd[STDOUT_TERM], STDERR_FILENO);
execl("/bin/sh","sh", (char*)NULL);
// Nothing below this line should be executed by child process. If so, …Run Code Online (Sandbox Code Playgroud) 我正在调试一个保险丝文件系统,该系统报告du. 原来,它是把st_size / st_blksize[*]到st_blocks了的stat结构。Linux 手册页stat(2)说:
struct stat {
…
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
…
};
Run Code Online (Sandbox Code Playgroud)
什么是st_blksize对,如果st_blocks是在512B块呢?
[*] 无论如何,这看起来是错误的,因为整数除法不考虑小数部分......
我目前有分叉两个进程的代码。第一个读取 http 流广播并将数据推送到管道(以 开头pipe()),以便第二个进程使用 OSS 读取、解码并输出到声卡。
我一直在尝试调试解码部分(单独的问题),并且遇到了这样一种情况,即当我打印管道时,它的文件描述符为 0。据我所知,这意味着标准输入。这是管道的一个已知问题,它可能会意外打开一个标准文件描述符吗?如果是这样,我该如何解决?
我的管道/叉代码如下。还有很多其他代码,我希望它们无关紧要。
//this is the "switch channel" loop
while(1)
{
/*create the pipes
*
* httpPipe is for transfer of the stream between the readProcess and the playProcess
*
* playPPipe is for transfer of commands from the main process to the playProcess
*
* readPPipe is for transfer of commands from the main process to the readProcess
*
*/
if(pipe(httpPipe) == -1)
{
cout << "ERROR:: Error creating httpPipe: " …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用其 API 提取有关 github 存储库的一些信息,显然jq是要走的路。我可以使用此命令查看所有可用信息:
curl 'https://api.github.com/repos/tmux-plugins/tpm' | jq
Run Code Online (Sandbox Code Playgroud)
输出:
{
"id": 19935788,
"node_id": "MDEwOlJlcG9zaXRvcnkxOTkzNTc4OA==",
"name": "tpm",
"full_name": "tmux-plugins/tpm",
"private": false,
"owner": {
"login": "tmux-plugins",
"id": 8289877,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjgyODk4Nzc=",
"avatar_url": "https://avatars.githubusercontent.com/u/8289877?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tmux-plugins",
"html_url": "https://github.com/tmux-plugins",
"followers_url": "https://api.github.com/users/tmux-plugins/followers",
"following_url": "https://api.github.com/users/tmux-plugins/following{/other_user}",
"gists_url": "https://api.github.com/users/tmux-plugins/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tmux-plugins/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tmux-plugins/subscriptions",
"organizations_url": "https://api.github.com/users/tmux-plugins/orgs",
"repos_url": "https://api.github.com/users/tmux-plugins/repos",
"events_url": "https://api.github.com/users/tmux-plugins/events{/privacy}",
"received_events_url": "https://api.github.com/users/tmux-plugins/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/tmux-plugins/tpm",
"description": "Tmux Plugin Manager",
"fork": false,
"url": "https://api.github.com/repos/tmux-plugins/tpm",
"forks_url": "https://api.github.com/repos/tmux-plugins/tpm/forks",
"keys_url": "https://api.github.com/repos/tmux-plugins/tpm/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/tmux-plugins/tpm/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/tmux-plugins/tpm/teams", …Run Code Online (Sandbox Code Playgroud) 为什么没有 Unix API?我的意思是,因为有 Windows API。
我知道 Unix 世界中的很多东西都是模块化的,这些东西放在一起就形成了一个完整的系统。这听起来不错,但是当您尝试制作本机 Unix 应用程序时确实会产生一些问题。
例如,你想用一个很酷的名字 WP 编写一个漂亮的文字处理器。Windows 版本的 WP 将通过调用 Windows API 来构建。您可以直接用 C 编写代码,也可以使用各种包装库中的任何一种。但是,该程序仍然必须通过调用 winapi 来构建,它提供了程序员构建 Windows 应用程序可能需要的每一个功能,从基本系统调用到 GUI、3D、多媒体或其他任何具有十多年向后兼容性的东西。如果不是这样,Wine 永远不会存在。
现在你想创建一个 Unix 版本的 WP。标准 C 和 C++ 库以及 POSIX API 非常稳定,并且在任何 Unix 变体中都得到很好的支持。当您尝试执行更多操作时会出现问题。所以你需要为 WP 创建一个窗口,但是如何呢?有 X11,但这不是唯一的。人们认为应该更换 X11,现在正在制作两个不兼容的替代品,Wayland 和 Mir。即使对于 X11,也有 Xlib 和 xcb。xcb 声称它们“更好”,在某些方面确实如此,但是文档在哪里?您最终选择 Xlib 来完成任务,但 X11 标准本身仅定义了非常基本的功能。您对 GUI 应用程序期望的任何其他内容(例如窗口事件或剪贴板支持)都需要通过调用来处理扩展XInternAtom. 这句话只是我个人的看法,但在X中使用Atoms是非常不直观的。另一个问题是并不是每个 X 的窗口管理器都很好地支持这些扩展。因此,让我们将这种肮脏的事情留给 GTK+ 和 Qt 的开发人员,他们会破坏每个新版本的向后兼容性。是否有可能在 Linux 中支持便携式拖放?
在我看来,Unix 社区真的在桌面世界中杀死了自己。我知道我提到的事情甚至对设置 BSD 服务器都没有关系,但是如果您尝试构建便携式本机 Linux 应用程序,则很重要。
是什么造成了这一切?真的有努力清理和标准化现代 Unix 桌面环境的东西吗?为什么没有 Unix API?会有一个吗?
我刚刚读了一个 ABI 的例子。这是正确的吗
ABI 与 API 类似,不同之处在于 ABI 是机器语言,而 API 是高级编程语言
ABI 是由机器语言编译库提供并属于其的接口吗?(如果我没猜错的话,一个自制的编译库提供了它的ABI(参见上面的例子)。操作系统可以被视为一个编译库,从而为应用程序访问其系统调用服务提供了自己的ABI。)
上面的例子并没有提到自制编译库的ABI是否依赖于操作系统。
https://en.wikipedia.org/wiki/Application_binary_interface但是提到了操作系统:
ABI 涵盖以下详细信息:
处理器指令集(详细信息如寄存器文件结构、堆栈组织、内存访问类型等)
处理器可以直接访问的基本数据类型的大小、布局和对齐方式
调用约定,控制函数参数的传递方式和返回值的检索方式;例如,是否所有参数都在堆栈上传递,或者某些参数在寄存器中传递,哪些寄存器用于哪些函数参数,以及堆栈上传递的第一个函数参数是首先还是最后压入堆栈
应用程序应如何对操作系统进行系统调用,如果 ABI 指定直接系统调用而不是对系统调用存根的过程调用,则系统调用号
而对于完整的操作系统ABI来说,则是目标文件、程序库等的二进制格式。
编译库的 ABI 是否取决于操作系统?(我想不会。即使编译库通过操作系统的 ABI 使用系统调用服务,依赖于操作系统(的 ABI)的是编译库而不是其 ABI。)
编译库的 ABI 可以独立于操作系统(的 ABI)吗?
谢谢。