は、私は2つのthreads.Iの間で通信されるいくつかの割り込みや信号はサーフィンとtgkillキル、tkill、のようないくつかのシステムコールを発見し、私のrequirmentをraise.Butている中でいくつかのサンプルprogrmasについて知りたいこと割り込みとして動作するはずです。私のコードでは、この呼び出しをブロックしています。2つのスレッド間で割り込みや信号を送信する方法は?プロセスを殺すことではありません
fcntl(fd, F_SETFL,0);
read(fd,&dataReceived.Serial_input,1);
私の要件に似たサンプルコードです。 plsは事前にshare.Thanks
私のコードではない:
void *serial_function(void *threadNo_R)
{
int ImThreadNo = (int) threadNo_R;
fd = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NDELAY);//
if (fd == -1)
{
/* Could not open the port. */
perror("open_port: Unable to open /dev/ttyUSB1 - ");
}
fcntl(fd, F_SETFL,0);
while(1)
{
read(fd,&dataReceived.Serial_input,1);
printf("\n From serial fn: Serial_input is:%c\n",dataReceived.Serial_input);
dataReceived.t2=dataReceived.Serial_input;
if(V_buf.power_window_data.front_right_up>=1)
{
sprintf(cmd,"Window is raising=%d",V_buf.power_window_data.front_right_up);
do
{
writenornot = write(fd, &cmd[spot], 1);
spot++;
} while (cmd[spot-1] != '\0');
spot=0;
//
if (writenornot < 0)
{
printf("Write Failed \n");
}
else
printf("Write successfull \n");
// write(fd,"DOWN",4);
}
print_screen=1;
}
}
はのFuncを受信:
void *receive_function(void *threadNo_R)
{
int ImThreadNo = (int) threadNo_R;
while(1)
{
if(msgrcv(R_msgid,&V_buf,sizeof(struct vehicle)+1,1,0) == -1)
{
printf("\n\nError failed to receive:\n\n");
}
}
}
私はシリアル機能によって処理されなければならない機能を受け取るからの信号を送りたいです。
あなたは、非ブロッキングIOと 'SELECT'と長期的には幸せになりますが、コードに最小限の変更のためにあなたが既に持っている、' tkill'は何をしたいです - あなただけの 'SIGUSR1のため_handler_をインストールする必要があります'、restart_システムコールには設定されていません。 – zwol
ハンドラSIGUSR1のインストール方法は? – Sri
あなたはあなた自身でその質問に答えることができます。まず、 'sigaction'マンページを読んでください。 – zwol