我正在使用node.js运行我的教授在我的chrome上给出的一个应用程序.发生了一些错事,但我不知道,因为我是一名新秀.结构如下:
/app
/models
answers.js
questions.js
sessions.js
user.js
passport.js
qmanage.js
routes.js
/config
auth.js
database.js
mcd.js
package.json
/public
some css png fonts jpg document
qloader.js
server.js
/views
some ejs document
Run Code Online (Sandbox Code Playgroud)
首先,它显示了这个问题:
module.js:457
throw err;
^
Error: Cannot find module 'mongoose'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/shen/Desktop/os/cse303.p2/server.js:2:16)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
Run Code Online (Sandbox Code Playgroud)
然后,基于此帮助Node.js错误错误:找不到模块'mongoose'我npm install mongoose在项目的根路径中运行.然后我有以下错误:
dyn143030:cse shen$ node server.js
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用Mac OS来实现命令排序功能的一部分:我的部分代码如下:
int compare(const void *p, const void *q) {
return strcmp(*(char **)p, *(char **)q);
}
void sort_file(char *filename, int unique, int reverse) {
/* TODO: Complete this function */
/* Note: you will probably need to implement some other functions */
char buf[1024][1024];
int i=0;
FILE * fp;
if(!(fp=fopen(filename,"r"))){
perror("Open error!");
exit(0);
}
while(fgets(buf[i],1024,fp)){
printf("%s",buf[i]);
i++;
}
qsort(buf, i, sizeof(char *), compare);
}
Run Code Online (Sandbox Code Playgroud)
结果总是显示segmentation fault: 11
任何人都可以告诉我这是什么问题以及如何修改它?
我还是想知道,如果我不知道一行和文件中代码的最大大小,如何定义我的数组?
我从这个页面得到了这个想法:http: //www.anyexample.com/programming/c/qsort__sorting_array_of_strings__integers_and_structs.xml
我在 Mac OS 上运行 C 程序。我的程序的一部分如下。此代码在 sigint 信号上运行良好,但无法在 sigkill 信号上运行。
void sigkill(int sig){
/*some code neglected*/
exit(0);
}
void sigint(int sig){
flag=1;
}
void alive(void) {
signal(SIGINT, sigint);
signal(SIGKILL, sigkill);
alarm(10);
while(1){
//printf("%d\n",flag);
sleep(1);
if(flag==1){
printf("no\n");
flag=0;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有四个问题:
起初我没有写sleep(1),它可以进入函数sigint(),并改变标志值,我从printf中可以看到。然而,没有像我预期的那样输出“no”。
添加睡眠功能后,效果很好。我想 while 循环会每 1 秒检查一次 flag,如果 flag=1 则输出“no”。但是,每次按 ctrl+c 时似乎都会输出“no”。为什么连一秒钟都不等?
问题是“你不应该使用'sleep()'来等待10秒。使用alarm(),加上一个循环。” 我想知道如何在没有 sleep() 的情况下实现这一点。
Kill 命令无法调用 sigkill 函数,如何解决这个问题?