I am doing something a bit weird but i want it fully synchronized. So i thought of asking your help. I have the following:
printf("My name is:");
system("echo syntax_Error");
printf("I am 17 yrs old\n");
this is quite abstract instead of echo I am executing a software that gives me an output, so execution time is unpredictable, but the order is the same. I want a printf then system call then printf such that they would come aligned as such
My name is syntax_Error I am 17 yrs old\n
I tried this order without locks but it didn't work which is quite obvious, or if it did sometimes it is unpredictable. I am new to synchronization structures so I would like your input.
cheers!=)
If you're thinking about threading and mutual exclusion (synchronisation) in C then look at POSIX threads. (man pthread).
As others have said to get your strings in the right order flush stdout. If you're on an OS with 'echo' that supports -n (no newline) this does what you're after.
Rather than just use 'system' also look at 'execve' etc. 'man execve'