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 08-11-2006, 08:46 AM   #1
herbertgnanaraja
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Rep: Reputation: 0
c in linux


I am using c language under linux. I want to run more than one processes simultaneously in background in a single terminal. What i am needed really is how to get a single character input from the keyboard to that processes running in the background.
 
Old 08-11-2006, 09:10 AM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
are you asking about threading in c? or just running multiple processes from one console
 
Old 08-11-2006, 09:58 AM   #3
apolinsky
Member
 
Registered: Oct 2004
Location: Brooklyn
Distribution: Slackware 15;
Posts: 439

Rep: Reputation: 46
Background processes are created by including an & after invoking the program. If a program is named a.out you would start it with ./a.out & . There is a space after the invocation of the program. You can end the backgrounding with an fg (foreground) command. If there are multiple backgrouded programs you will be able to choose between them.
 
Old 08-11-2006, 12:04 PM   #4
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
Quote:
Background processes are created by including an & after invoking the program.
Well.. that's backgrounding from command line. However, a program can go into background via fork() or daemon() directly. Please detail your problem though ..

#1. How do the programs go into background?
#2. When, where and why do they need to get a character from the user?
 
Old 08-12-2006, 03:31 AM   #5
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Threading and multiple processes are not the same thing either.

If we talk threading, the main thread and the background thread can share come kind of global variable, using mutexes to stay out of each other's way. A better solution if to use queues (I suppose that NPTL has those, I'm used to Python).

As for multiple processes, you'd use mmap, pipes or the like.
 
Old 08-12-2006, 03:48 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,788

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by herbertgnanaraja
What i am needed really is how to get a single character input from the keyboard to that processes running in the background.
Perhaps what you are looking for is the suspend character, usually Control-Z, which allows to bring a running process to the background, with the bg, and later to the foreground, with the fg commands.
 
Old 08-15-2006, 09:11 AM   #7
herbertgnanaraja
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by introuble
Well.. that's backgrounding from command line. However, a program can go into background via fork() or daemon() directly. Please detail your problem though ..

#1. How do the programs go into background?
#2. When, where and why do they need to get a character from the user?
Thank you for your response

I just made the programs to run in the background by "./a.out &".
But i need the backgound process to get the input from the keyboard(NOT CTRL+Z,etc....)

Also tell me how to get the input in non-canonical mode
 
Old 08-15-2006, 09:36 AM   #8
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Background process does not take any keyboard input. At least directly. You need to bring it back into foreground and then may handle the input data again. Alternatively, the process (still in background) can use any interprocess communication method (like pipe or local socket) to get the data from another process.
 
Old 08-15-2006, 10:31 AM   #9
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
what is the goal here, a keylogger?
 
  


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
link dies intermittently-seemingly at random- between win<->linux not linux<->linux?? takahaya Linux - Networking 10 03-09-2007 10:37 PM

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

All times are GMT -5. The time now is 06:39 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