LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-03-2005, 05:48 AM   #1
dr_sad
Member
 
Registered: Apr 2005
Location: Russia, West Sibirian town Surgut.
Distribution: SuSE 10.0
Posts: 38

Rep: Reputation: 15
Creating the log-file


Hi, all
I have written the socket program. It listen on the TCP port, receive the commands from the clients and make the system operations: add, delete and chpass users.
I have made it "daemon" and use fork() in it to serve more than one clients simultaneously.
Every child process write the log message to the log file /some/where/in/the/file/system/log.

How should I write to the file if the several process will be write to that file simultaneously?

Many thanx.
Sad Grablin.

P.S. sorry, i work in C.

Last edited by dr_sad; 04-03-2005 at 05:53 AM.
 
Old 04-03-2005, 11:55 AM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Make one process that will deal with the log file and pass the messages to it using IPC routines. If you start with reading 'man msgsnd' you should understand how to do it fast.
 
Old 04-03-2005, 09:32 PM   #3
dr_sad
Member
 
Registered: Apr 2005
Location: Russia, West Sibirian town Surgut.
Distribution: SuSE 10.0
Posts: 38

Original Poster
Rep: Reputation: 15
Thank You, Mara, for your reply. I'll try to read 'man msgsnd'. But what about flock ? May it be useful?
 
Old 04-06-2005, 03:33 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You can also use locks, but I don't recommend it. It's easy to make the whole thing stop because of lock (when a number of processes wants to write and one is keeping the file. When using messages you don't need to deal with this problem.
 
Old 04-06-2005, 05:27 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Would semaphores be an option? (man semget)
And how would this compare to locks and message queues?
 
Old 04-12-2005, 05:01 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Locks lock files. In this case you may lock the log file. Message queues may be used to pass the data to be written to the log file to one process/thread from many others. Semaphores - if you have a semaphore that protects the log file (like lock, but at different level) and only teh thread that has it writes in, it will also work.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a log file to post to corfrm all components for dvd plaback cjae SUSE / openSUSE 1 07-12-2005 05:36 PM
Creating a Log file nguye103 Linux - Newbie 1 10-21-2004 06:16 PM
Creating a log file in unix?? linux_dejan Programming 3 09-03-2004 10:56 PM
Cron - not creating log file t3___ Linux - Newbie 3 02-26-2004 06:50 PM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration