LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c in linux (https://www.linuxquestions.org/questions/programming-9/c-in-linux-472952/)

herbertgnanaraja 08-11-2006 08:46 AM

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.

xhi 08-11-2006 09:10 AM

are you asking about threading in c? or just running multiple processes from one console

apolinsky 08-11-2006 09:58 AM

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.

introuble 08-11-2006 12:04 PM

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?

uselpa 08-12-2006 03:31 AM

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.

jlliagre 08-12-2006 03:48 AM

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.

herbertgnanaraja 08-15-2006 09:11 AM

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

Mara 08-15-2006 09:36 AM

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.

xhi 08-15-2006 10:31 AM

what is the goal here, a keylogger?


All times are GMT -5. The time now is 05:53 AM.