ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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.
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,788
Rep:
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.