UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 12th, 2004, 05:19 AM
bulsona bulsona is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 bulsona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 31 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old August 12th, 2004, 02:09 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
system()

Reply With Quote
  #3  
Old August 13th, 2004, 01:35 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 49 m 57 sec
Reputation Power: 9
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 !

Reply With Quote
  #4  
Old August 13th, 2004, 03:11 AM
bulsona bulsona is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 bulsona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 31 sec
Reputation Power: 0
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

Reply With Quote
  #5  
Old August 13th, 2004, 05:11 AM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
You need a
lseek(filedes,0,SEEK_SET);
in front of the while statement.

Reply With Quote
  #6  
Old August 13th, 2004, 04:05 PM
bulsona bulsona is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 bulsona User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 31 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Sending conrol back to Original program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway