在Raspberry Pi 2上使用Raspbian,我发现我可以使用typedef struct{
char* rheaders[500][500]; //HTML headers
char* curltemp[50000]; //Temp string space for CURL function
char* alias[5000];
char* idx[5000];
char* redirurl[5000];
unsigned long rhdrct;
unsigned long idxct;
unsigned long aliasct;
unsigned long notrail;
unsigned long nologall;
unsigned long httpstatus;
unsigned long print;
}Iconfig;
static Iconfig conf;
static CURL *curl;
static size_t curlH(char *buffer,size_t size,size_t nitems,void *userdata){
//store data as it comes in. This works
snprintf((char*)conf.rheaders[conf.rhdrct++],(size*nitems)-1,"%s\0",(char*)buffer);
return (size*nitems);
}
static int getnewURL(request_rec *r){
curl=curl_easy_init();
if (curl){
struct curl_slist *chunk=NULL;char cc[1000];
//This header below isn't being sent with request
chunk = curl_slist_append(chunk, "x-custom: 1;");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
//Request from server this code is executed on
curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1/test");
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_HEADERDATA,conf.curltemp);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION,curlH);
CURLcode res=curl_easy_perform(curl);
curl_easy_cleanup(curl);
//iterate and display all headers after request is done
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, r->server, "Headers...");
unsigned long i;
for (i=0;i<conf.rhdrct;i++){
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, r->server, "%d %s",i,conf.rheaders[i]);
}
}
}
static int handler(request_rec *r){
// This happens on every request including those from CURL
if (!ap_is_initial_req(r)){return DECLINED;}
//check headers to see if x-custom is set to 1
const char*a=apr_table_get(r->headers_in,"x-custom");
if (a){
if (strcmp("1",a)==0){
//pass on new x-received header sent via CURL and process normally
//but this stage never happens
char b[1000];sprintf(b,"%s recvd\0",a);
apr_table_set(r->headers_out,"x-received:",b);
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, r->server, "Subrequest");
return DECLINED;
}
}
//execute request in CURL and stop this apache process
getnewURL(r);
return DONE;
}
,然后在表中添加一行//but this stage never happens
来启动节点进程。
我无法弄清楚如何快速杀死这个过程。我在crontab -e
中没有看到它。在哪个流程下运行?
答案 0 :(得分:1)
Cron作业由cron
或crond
启动,这将生成sh
以运行您的命令。但是,您的命令分叉以在后台运行,然后完成执行,因此node
进程将重新分配给根进程init
。