Executing shell commands under multithreaded Linux app

Status
Not open for further replies.

spagthorpe

Ars Tribunus Angusticlavius
7,304
Okay, I didn't think this would be complicated, but I haven't gotten it to work....I figured I would try here.

I've got this app that runs interactive, starts several other processes using pThreads. Doesn't require keystrokes, but displays info in the terminal window that is important for the user to see. I also need to execute a system function during a certain event.

I have one of the threads call an outside system command, using the system() function, but this causes problems. It seems to knock the processes into a sleep state, and I get no further output.

What would be the best way to call an external function like this, without loosing my foreground process?
 

ix_wookiee

Ars Scholae Palatinae
677
well... depening on the program you're calling, you could just implement it your program.

IIRC, linux's threading system is pushing the bounds of posix compliency due to 'its not a thread, its just a process with shared io/memory/sig handlers' nature.

i wouldnt go the route of making a daemon program just to handle system() calls, mainly cause its a big pain :) logicly, you should be safe with fork()ing before creating all your threads in the main program. then smack the child with a SIGUSR1 or SIGUSR2 when it needs to call system(). maybe use a bit of shared memory/message queues if you need to pass data, or even pipe() if you dont feel like dicking with shmmem.
 
Status
Not open for further replies.