LinuxQuestions.org
Help answer threads with 0 replies.
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-02-2006, 05:17 PM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
catch signals from the command line


hello,
i am trying to write a daemon that listen in the background and catches commands from the command line. For example:
Code:
vim newtext.tex
I want my program to run before vim runs. This is possible?

The reason why I want to do this is because I'm writing a distributed program, where all the clients that run my daemon, can currently access a remote file system. So if vim is called I need to tell all the other clients that this file locked, or if the file is currently locked I want vim to open this as readonly.

let me know if this doesn't make sense,

thanks,
djgerbaor3
 
Old 04-02-2006, 06:07 PM   #2
cyber-worx
Member
 
Registered: May 2004
Location: England / Switzerland
Distribution: Gentoo, Ubuntu, Debian, Slackware
Posts: 138

Rep: Reputation: 15
I cant see how you could do that, aside of reading the bytestream for each tty which is a pain in the ass.

I think you need to look more into the design of your application.

Regards
-Rob
 
Old 04-02-2006, 06:15 PM   #3
astorm
LQ Newbie
 
Registered: Nov 2005
Distribution: Slackware
Posts: 23

Rep: Reputation: 15
You're going to need to do something lower-level than capturing the command line, because other programs can also open files. Sounds like you're going to need a listener at the filesystem level, but this is from someone with little filesystem experience. But if it's a remote filesystem, shouldn't it already have built-in mutex capabilities?
 
Old 04-02-2006, 06:16 PM   #4
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Original Poster
Rep: Reputation: 30
that is what i figure, thanks for the help, I think I'm just going design my own interface to the remote filesystem. For example, my daemon will have its own shell (or set of commands), and my users can type command to my program.

I have a dumb question: how can i redirect stderr to a log file. I want to do it in the program, not using shell scripts (i,.e. ./myprog >& out.dat)


thanks,

djgerbavor3

Last edited by djgerbavore; 04-02-2006 at 06:31 PM.
 
Old 04-02-2006, 07:03 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

To redirect stderr:

myprog 2> myfile.err

To redirect stdout and stderr to the same file:

myprog 1>&2 myfile.out

Here are more more details:

http://www.faqs.org/docs/abs/HTML/ioredirintro.html

'Hope that helps .. PSM

PS:
In case you were wondering, "myprog 1>&2 myfile.out" should be equivalent to "myprog 2>&1 myfile.out".

Last edited by paulsm4; 04-02-2006 at 07:06 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
51 characters only in the 1st Line of command line eggCover Linux - General 2 07-29-2004 01:28 PM
Catch signals C++ moyacuba Programming 2 03-18-2004 12:28 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 12:24 AM

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

All times are GMT -5. The time now is 06:53 PM.

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