简体   繁体   中英

C - running program accept input

This is a very beginner-level question in C. Don't know where to start looking/searching.

So, if I have a program continuously running in C, what is the best way to accept input through the command line into the program?

EX, mysql is already running, but you can process a command call

mysql SELECT * FROM *

Do I need a different program to write to file/stdin?enter code here

Clarification:

So, mysql seems to be able to take in commands while it is already running... is that possible in C?

Goal: I have some hooks into open gl es, and I want to run a continuous draw loop in the background, while having the ability to call commands such as

glhookprogram make "object1" model "triangle" program "default"
glhookprogram attr "object1" position "1.0, 1.0, 0.0" scale "2.0" rotation "45, 0, 0"

this way, I can have a node server run hw-accelerated animations in javascript on the rpi.

Looks like this is what you need (and I'm sorry - I won't be going into too much details as there are plenty of sources on the Web about that):

  1. A "server" - that would be your background process that stays running in memory and can accept and process commands (requests)
  2. A "client" - a (short-running?) process that can accept commands from user (GUI, command-line. Network? Other process?) and send requests to your "server"

This is not a trivial task for a beginner. I would suggest googling for "server-client" and for "inter-process communications" first and go from there.

The range of options to "accept input" into your server includes (but is not limited to) the following:

  1. (Windows) messages
  2. Shared memory and a command queue (producer-consumer)
  3. Shared file (just listing it here for completeness, I'd advise against this particular one for your case)
  4. Named pipes
  5. Sockets (thanks for reminding me of those in the comments, can't believe I missed that!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM