|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Sending conrol back to Original program
I am trying to write a program that monitors a file and prints it each time it changes.
In this, I am calling system call (execlp()) to print (cat) the program when the program modifies. But the control doesnt go back to the original program to keep monitoring the file. The original program gets control back only when ther is an error. Is there any other call that I should use to send back the control to the original program? |
|
#2
|
|||
|
|||
|
system()
|
|
#3
|
|||
|
|||
|
i read about 'tail -f', in unix,
you maybe, are trying 'c' why start a 'cat' in a 'execlp()' ? loock for [f]open && [f]print ! |
|
#4
|
|||
|
|||
|
Thanks for the suggestions.
I tried writing the above program like this But when I run it it prints the opened file contents, but when I modify the file again, it displays or may not display the file contents again... Can you tell me where the problem lies? IS there some problem with this code --- for(; ![]() { sleep(60); if(fstat(filedes,&stbuf) == -1){ fprintf(stderr,"could not stat file\n"); exit(1); } printf("try the second loop"); if(stbuf.st_mtime != last_time) { while((read(filedes,buffer,BUFSIZE)) > 0) { printf("%s\n",buffer); } } last_time = stbuf.st_mtime; } ********************************8 |
|
#5
|
|||
|
|||
|
You need a
lseek(filedes,0,SEEK_SET); in front of the while statement. |
|
#6
|
|||
|
|||
|
thanks a lot guys, my program is finally working now.
Without using lseek, the current position was set to end of the file. Thats why the while loop was not executing the next time. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Sending conrol back to Original program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|