Monday 15 June 2015

c - Unable to terminate forked process -



c - Unable to terminate forked process -

i have process has terminated using ctrl-c or sigint. in case cannot utilize ctrl-c physically keyboard, has done using kill command in c. code reads gpio input , starts , stops script record.sh , gstreamer command line script.

i want terminate kid process created in startvideorecording(). need start, stop, start, stop recording many times like. it's not one-off thing.

however, when alter gpio value , trigger stopallrecordings(), doesn't send sigint kid process. hangs there @ "sending interrupt gstreamer process.. status 0"

how can create sure video recording process terminated ctrl-c equivalent?

thanks.

here's code :

int main() { pollgpioswitch(&vn200); } void* pollgpioswitch(void* arg) { vn200* vn200 = (vn200*)arg; int fd; char buf[100]; char value; int videorecerror; bool videorecon = false; sprintf(buf, "/sys/class/gpio/gpio56/value"); while (keep_going) { fd = open(buf,o_rdonly); lseek(fd,0,seek_set); // move origin of file read(fd,&value,1); if (value=='0') { if (videorecon) { // recording on, switch off, end recording stopallrecordings(); videorecon = false; triggergpsinsthreadexit = 0; // reset variables printf("reset gpsins thread variables.\n"); } } else if (!videorecon) { // recording off, switch on, start recording if (pthread_create(&gpsinsloggingthread, null, rungpsins,(void*) vn200) != 0) { printf("error: fail create rungpsins thread\n"); } videorecerror = startvideorecording(); if (videorecerror == -1) pthread_exit(&videorecerror); videorecon = true; } usleep(500000); } close(fd); printf("exited polling!"); } int startvideorecording() { int error; error = 0; if ((avrecordingprocess = fork()) != -1) { switch (avrecordingprocess) { case -1: printf("error: fail create avrecordingprocess\n"); error = -1; case 0: execl("record.sh", "0", null); //system("//root//record.sh"); printf("error: fail execute avrecordingprocess\n"); error = -1; default: printf("video recording...process id %d\n", avrecordingprocess); break; } } else { printf("error: mainhost failed fork avrecordingprocess\n"); error = -1; } homecoming error; } void stopallrecordings() { int ret; file *infile, *outfile; int ch; printf("terminating kid processes..%d\n", avrecordingprocess); ret = kill(avrecordingprocess, sigint); printf("sending interrupt gstreamer process.. status %d\n", ret); int status; printf("wait gstreamer process %d end....", avrecordingprocess); wait(avrecordingprocess); printf("gstreamer ended.\n"); }

is possible starting multiple kid processes , sending sigint lastly kid process created , not before ones? type 'ps' , nail come in after starting programme , see how many processes have started.

c linux gpio

No comments:

Post a Comment