C 程序挂起,没有输出
我已经仔细研究这个程序很久了,不知道为什么它不起作用。我有理由相信它做的一切都是正确的,但它没有真正工作,而是在打印第一个提示后无限期地挂起,我就是不明白为什么。我现在几乎不知所措,所以如果有人能告诉我我做错了什么,我将不胜感激 它是C99,您需要mhash库来编译它(用于CRC32计算)。它非常便携,但我是在Linux上开发的不要在虚拟机中运行强>C 程序挂起,没有输出,c,daemon,C,Daemon,我已经仔细研究这个程序很久了,不知道为什么它不起作用。我有理由相信它做的一切都是正确的,但它没有真正工作,而是在打印第一个提示后无限期地挂起,我就是不明白为什么。我现在几乎不知所措,所以如果有人能告诉我我做错了什么,我将不胜感激 它是C99,您需要mhash库来编译它(用于CRC32计算)。它非常便携,但我是在Linux上开发的不要在虚拟机中运行 #define _BSD_SOURCE #include <stdio.h> #include <stdlib.h> #inc
#define _BSD_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <mhash.h>
/* WARNING: Do not debug this program. Halting on breakpoints at the wrong
* time can be extremely hazardous. YOU HAVE BEEN WARNED. */
/* Structures used to define our layout. Note the careful use of volatile;
* we don't want the compiler optimising away part of the invocation. */
typedef struct
{
const char name[7]; /* sigil at focus */
volatile int target; /* summoning point */
volatile char invocation; /* current char of invocation */
} focus_t;
typedef struct node
{
const char name[4]; /* name of node */
focus_t* center; /* points to the evocation focus */
struct node* cw; /* clockwise binding ring */
struct node* ccw; /* counterclockwise binding ring */
struct node* star; /* next node of star */
const char* linkname; /* name of star linkage */
volatile uint32_t angel; /* protective angel for this node */
} node_t;
/* The pentacle nodes are circularly linked in both directions to form
* a binding perimeter. In addition, they are singly linked to form a
* classic 'daemon trap' five-pointed star. Each node points towards the
* evocation focus (but not the other way around!) to enforce the geometry
* we want. The design is based heavily on the Pentagram of Solomon. */
struct
{
focus_t focus;
node_t node[5];
}
S =
{
/* None of the symbols for the pentacle are in Unicode. So we have to make
* do with Latin transcriptions. */
.focus = { "SOLUZEN", 0 },
.node = {
[0] = { "TE", &S.focus, &S.node[1], &S.node[4], &S.node[2], "BELLONY" },
[1] = { "TRA", &S.focus, &S.node[2], &S.node[0], &S.node[3], "HALLIY" },
[2] = { "GRAM", &S.focus, &S.node[3], &S.node[1], &S.node[4], "HALLIZA" },
[3] = { "MA", &S.focus, &S.node[4], &S.node[2], &S.node[0], "ABDIA" },
[4] = { "TON", &S.focus, &S.node[0], &S.node[3], &S.node[1], "BALLATON" }
}
};
/* Name of spirit to summon --- rot13'd for safety.
* (#65 from Crowley's translation of SHEMHAMPHORASH.)
* This is Andrealphus, he that has dominion over menusuration, astronomy and
* geometry. He seems fairly non-threatening. */
const char spiritname[] = "NAQERNYCUHF";
int rot13(int c) { return 'A' + (((c - 'A') + 13) % 26); }
/* We invoke the following names around the circle as a protective measure.
* Strictly these should be in Hebrew script, but as the computer is a dumb
* instrument we're relying on the symbolism rather than the actual literal
* meaning themselves. Plus, working in RTL is a pain. */
const char* angels[] = {
"Kether", "Eheieh", "Metatron", "Chaioth ha-Qadesh",
"Rashith ha-Gilgalim", "Chokmah", "Jah", "Ratziel", "Auphanim",
"Masloth", "Binah", "Jehovah Elohim", "Tzaphkiel", "Aralim",
"Shabbathai", "Chesed", "El", "Tzadkiel", "Chasmalim", "Tzadekh",
"Geburah", "Elohim Gibor", "Khamael", "Seraphim", "Madim",
"Tiphareth", "Eloah Va-Daath", "Raphael", "Malachim", "Shemesh",
"Netzach", "Jehovah Sabaoth", "Haniel", "Elohim", "Nogah", "Hod",
"Elohim Sabaoth", "Michael", "Beni Elohim", "Kokab", "Yesod",
"Shaddai El Chai", "Gabriel", "Cherubim", "Levanah"
};
const int angelcount = sizeof(angels)/sizeof(*angels);
/* Place the next angel on the pentacle. */
static void updatepentacle()
{
static int angelnode = 0;
static int angelindex = 0;
const char* angel = angels[angelindex++];
angelindex %= angelcount;
/* Hash the angel's name to reduce its essence to 32 bits (which lets us
* copy the angel bodily into the pentacle node. */
uint32_t angelhash;
MHASH td = mhash_init(MHASH_CRC32);
mhash(td, angel, strlen(angel));
mhash_deinit(td, &angelhash);
S.node[angelnode].angel = angelhash;
angelnode = (angelnode + 1) % 5;
}
int main(int argc, const char* argv[])
{
/* Lock the evocation into memory, to prevent it from being paged out
* while the spirit has manifested --- which would be bad. */
int e = mlock(&S, sizeof(S));
if (e != 0)
{
fprintf(stderr, "Unable to lock evocation, refusing to run\n");
exit(1);
}
/* Actually perform the invocation: continually cycle the spirit's
* name into the evocation focus (while maintaining our pentacle
* integrity!) until something shows up in the target of the
* evocation focus. */
printf("Summoning...\n");
do
{
for (int i = 0; i < sizeof(spiritname)-1; i++)
{
S.focus.invocation = rot13(spiritname[i]);
updatepentacle();
usleep(100); /* don't CPU-starve our spirit */
}
}
while (S.focus.target == 0);
printf("Summoning successful! %d\n", S.focus.target);
/* Our spirit's arrived! Dismiss it immediately by using a null
* invocation. Keep going until the evocation focus remains empty.
* FIXME: a particularly mean spirit might find a way to hide. Until
* we can sort this out, only summon relatively benign ones. This is
* probably safe anyway, as when the process terminates the spirit's
* address space will be nuked, taking the spirit with it. */
printf("Dismissing...\n");
do
{
S.focus.target = 0;
for (int i = 0; i < 1000; i++)
{
S.focus.invocation = 0;
updatepentacle();
}
}
while (S.focus.target != 0);
printf("Done.\n");
return 0;
}
\define\u BSD\u源
#包括
#包括
#包括
#包括
#包括
/*警告:不要调试此程序。在错误的位置停止断点
*时间是极其危险的。你已经被警告了*/
/*用于定义布局的结构。注意挥发油的小心使用;
*我们不希望编译器优化调用的一部分*/
类型定义结构
{
const char name[7];/*焦点处的符号*/
易变int目标;/*召唤点*/
volatile char调用;/*调用的当前字符*/
}聚焦;
类型定义结构节点
{
常量字符名称[4];/*节点名称*/
焦点\u t*中心;/*指向唤起焦点*/
结构节点*cw;/*顺时针绑定环*/
结构节点*ccw;/*逆时针绑定环*/
结构节点*星形;/*星形的下一个节点*/
常量字符*linkname;/*星形链接的名称*/
volatile uint32_t angle;/*此节点的保护角*/
}节点t;
/*五角星节点在两个方向上循环连接形成
*有约束力的周界。此外,它们单独连接形成一个
*经典的“精灵陷阱”五星。每个节点都指向
*唤起焦点(但不是相反!)以强制几何体
*我们想要。该设计主要基于所罗门的五角星*/
结构
{
关注焦点;
节点[5];
}
=
{
/*五角星的符号都不是Unicode的,所以我们必须
*用拉丁文抄本*/
.focus={“SOLUZEN”,0},
.node={
[0]={TE',S.focus,&S.node[1],&S.node[4],&S.node[2],“BELLONY”},
[1] ={“TRA”、&S.focus、&S.node[2]、&S.node[0]、&S.node[3]、“HALLIY”},
[2] ={“GRAM”、&S.focus、&S.node[3]、&S.node[1]、&S.node[4]、“HALLIZA”},
[3] ={MA',S.focus,&S.node[4],&S.node[2],&S.node[0],“ABDIA”},
[4] ={“TON”、&S.focus、&S.node[0]、&S.node[3]、&S.node[1]、“BALLATON”}
}
};
/*召唤灵魂的名字——为了安全而轮换。
*(#65摘自克劳利翻译的舍姆罕默拉什。)
*这就是安德烈·阿尔弗斯,他统治着美努塞翁、天文学和文学
*几何学。他似乎没有什么威胁*/
const char spirtname[]=“NAQERNYCUHF”;
introt13(intc){返回'A'+(((c-'A')+13)%26);}
/*我们在圆圈周围使用以下名称作为保护措施。
*严格来说,这些应该是希伯来文,但由于计算机是一个哑巴
*我们依靠的是象征而不是实际的文字
*意味着他们自己。另外,在RTL工作很痛苦*/
常量字符*天使[]={
“凯瑟”、“埃希耶”、“梅塔特隆”、“查伊奥哈卡德什”,
“拉希特·哈·吉尔加利姆”、“乔克马”、“贾”、“拉齐尔”、“奥法尼姆”,
“马斯洛”、“比纳”、“耶和华以禄恒”、“察法基尔”、“亚拉琳”,
“沙巴赛”、“切塞”、“厄尔”、“扎德基尔”、“查斯马利姆”、“扎德赫”,
“盖伯拉”、“伊洛希姆·吉伯”、“哈迈尔”、“六翼天使”、“玛迪姆”,
“提法勒斯”、“伊洛亚·瓦·达特”、“拉斐尔”、“马拉奇姆”、“示麦”,
“尼撒”、“耶和华撒保”、“哈聂”、“以罗欣”、“诺迦”、“荷德”,
“Elohim Sabaoth”、“Michael”、“Beni Elohim”、“Kokab”、“Yesod”,
“Shaddai El Chai”、“Gabriel”、“Cherubim”、“Levanah”
};
const int angelcount=sizeof(天使)/sizeof(*天使);
/*把下一个天使放在五角星上*/
静态void updatePentage()
{
静态节点=0;
静态指数=0;
常量字符*天使=天使[angelindex++];
angelindex%=angelcount;
/*散列天使的名字,将其本质减少到32位(这让我们
*将天使身体复制到五角星节点*/
uint32_t angelhash;
MHASH td=MHASH_init(MHASH_CRC32);
mhash(td、angel、strlen(angel));
mhash_Denit(td和angelhash);
S.node[angelnode].angel=angelhash;
angelnode=(angelnode+1)%5;
}
int main(int argc,const char*argv[]
{
/*将调用锁定到内存中,以防止其被调出
*当灵魂显现出来的时候——那是不好的*/
int e=mlock(和S、sizeof);
如果(e!=0)
{
fprintf(stderr,“无法锁定调用,拒绝运行\n”);
出口(1);
}
/*实际执行召唤:不断循环圣灵的生命
*名称进入唤起焦点(同时保持我们的五角星
*完整性!),直到在目标
*唤起焦点*/
printf(“传唤…\n”);
做
{
对于(int i=0;i