LINUX.ORG.RU

ipc+system=мистика ?


0

0

Два процесса обмениваются сообщениями по ipc.


Запускается несколько процессов-клиентов, помещаюшие сообщения
в очередь, такого вида:


#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#define MSGKEY 11111

struct msgform {
long mtype;
char mtext[10];

};

int main(int argc,char *argv[])
{

if (argc<2)
{
printf("You must, input ASIN, man !\n");
return 1;

}
struct msgform msg;
int msgid,pid,*pint;
key_t key=ftok("./",1);
msgid = msgget(key,0777);

printf("%d",msgid );

strcpy(msg.mtext,*(++argv));
printf("%s\n",msg.mtext);
pid=getpid();


msg.mtype=1;

msgsnd(msgid,&msg,sizeof(msg.mtext),0);
return 0;
}


//-------------------------------------------------------------------



Эти сообщения получает процесс сервер. Он запускает внешнюю комманду
(скрипт PHP) и передает в нее полученное сообщение. Процесс сервер:


#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <errno.h>


struct msgform
{
long mtype;
char mtext[10];


}msg,msg2;
int msgid;
int main()
{



int i,pid,*pint;
extern cleanup();

for (i=0;i<20;i++)
signal(i,cleanup);

key_t key=ftok("./",1);
msgid=msgget(key,IPC_CREAT);

for(;;)


{

msgrcv(msgid,&msg,sizeof(msg.mtext),1,0);
char cmd[50];



strcpy(cmd,"./updater.php5");
strcat(cmd," ");
strcat(cmd,msg.mtext);

system(cmd);






}





return 0;
}
cleanup()
{
msgctl(msgid,IPC_RMID,0);
exit(0);

}

А теперь вопрос знатокам. Какого ..... программа прерывается сразу после первого запуска system (т.е. внешняя комманда выполняется, но только один раз) ? Если не использовать system, то все будет работать. Как только я запускаю ЛЮБУЮ комманду с пом. system
в цикле, все слетает: цикл прерывается, программа завершает работу.









У тебя оригинальный обработчик сигналов )
man system:
The system() function hands the argument string to the command interpreter sh(1).  The calling process waits for the shell to finish executing the command, ignoring SIGINT and SIGQUIT, and blocking SIGCHLD.

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.