killdurst
asked on
How to run a c program (that accepts an argument) in the background and saves all printfs to a file?
Hi, I'm running a c program from IBM (http://www.ibm.com/developerworks/linux/library/l-inotify/index.html) on my Linux machine to monitor a folder.
The command I ran to monitor a folder is...
would result in some output in the first console. (From all the printfs in the c program.)
So now I want to save all of the output to a file. I tried to execute the following command...
How to save all of the printf output from the c program into a file?
I would also like to run this program in the background, but lets solve the logging part first.
Thanks!
The command I ran to monitor a folder is...
/root/inotify-sample/inotify_test /home/temp/folderToWatch
In a second console, any changes I make to "/home/temp/folderToWatch"So now I want to save all of the output to a file. I tried to execute the following command...
/root/inotify-sample/inotify_test /home/temp/folderToWatch > /root/watchedFolders/log.txt
But after making changes to the "folderToWatch" folder (add/modify/delete files), there is no output in both the console and "log.txt".How to save all of the printf output from the c program into a file?
I would also like to run this program in the background, but lets solve the logging part first.
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi, I tried the following command...
nohup /root/inotify-sample/inoti fy_test /home/temp/folderToWatch >> /root/watchedFolders/log.t xt 2>&1 &
"cat /root/watchedFolders/log.t xt" produces the following...
nohup: ignoring input
When I create/modify/delete files in "folderToWatch", "log.txt" is not updated with the printfs from the c program. :(
Do let me know if there's an error or something in the command I ran... Thanks!
nohup /root/inotify-sample/inoti
"cat /root/watchedFolders/log.t
nohup: ignoring input
When I create/modify/delete files in "folderToWatch", "log.txt" is not updated with the printfs from the c program. :(
Do let me know if there's an error or something in the command I ran... Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yup, I did get output on screen before making the fflush change. That's why it's so weird that I couldn't save the output to a log file...
Not sure if it matters, but this C program is a program that will run continuously and will exit only when you kill the process.
Not sure if it matters, but this C program is a program that will run continuously and will exit only when you kill the process.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adding fflush helped solved the issue. Thanks to everyone who participated!
ASKER
The files in the tgz are...
event_queue.c
inotify_test.c
inotify_utils.c
Makefile
README
event_queue.h
inotify_utils.h
On my Linux, I executed "make -f Makefile" to make the executable "inotify_test".
The printfs would appear correctly if I were to run...
/root/inotify-sample/inoti
Just let me know if you require more information. If you can download and test the program on your Linux, that'd be great! Thanks!