Call the same instance of the program?

I am creating a C program that is called from a shell script when a specific event occurs. Program C receives an argument from a shell script as follows:

> ./c-program.bin HELLO

Now the C program runs until it receives a specific character as an argument. The problem is that if a second event occurs, and the C program is now called like this:

./c-program.bin WORLD

Then this is a new instance of the program that starts, which does not know anything about the line from the first event. What I would like to achieve looks something like this:

[EVENT0] ./c-program.bin HELLO
[EVENT1] ./c-program.bin WORLD
[EVENT2] ./c-program.bin *

c-program output:

HELLO WORLD

Any ideas on how to have only one instance of the program? The platform is Linux. Thus, the project is in the planning phase, I do not have a specific code yet, I first try to deal with various problems.

+3
5

, , , script

script , '*', c.

, script script, :

secondscript HELLO
secondscript WORLD
secondscript *

script *, c

./c-program.bin HELLO WORLD

, . script 10 . /script:

passedstring = args[0]

if passedstring = "*"
    string cache = readcontents(cachefile)
    call c program passing cache
    clearcontents(cachefile)
else
    append(cachefile, passedstring)   

dancin, , , :)

+1

" " , ? , . ( , ).

+1

pid, - . , , ( pid + ). , , . , , (fork).

, pidfile , . argv [i] ​​ , .

- unix , mysql.sock.

+1

, , , . , , "", , . .

+1

, , . , , "" - , .

:

  • fifo . , , fifo, , *, fifo, *.
  • ( , ) fifo .
  • *, fifo , , - *.
+1

Source: https://habr.com/ru/post/1770902/


All Articles