I need to run two mains together.
In the principal main I use spawnl to create a process of the executable of the other main( that has to run together ).
How can I do it?
What is the type of the file wich is the executable of the program?
I’m using QNX Momentics in Windows connected to QNX 6.4.
I think that I explained correctly my problem, sorry about my english.
If you want two copies of the same program to run together just start two copies.
If you want one program to create a second copy of itself then look at fork().
If you want one program to spawn a different program then look at the spawn* functions.
If you want one executable to contain two or more threads then look at pthread_create() and the associated pthread* family of functions.
There are examples in the docs for most of these, however when you get into the pthread functions it can become quite complex depending on what your needs are.
"If you want one program to spawn a different program then look at the spawn* functions. "
I’m using it, but I don’t know where i put the second main.
If I put in the same folder it not runs. If I put in other folder, it doesn’t call the second main.
Now the second main is in another project, but it’s not working.
I think that is some configuration, some detail, in Momentics. I guess is nothing in the code.
I’m not new… I’m think that’s weird too, two mains… but my chief sad to me change a project that was in QNX4 to QNX6… and that was working… I’m not a experienced programmer… that stuff of process, thread is new to me.
Chief can be wrong If there is more then one main() in the same program, the linker will only use one and will ignored the others. More then one main() in the same program is very very very wrong…
Try specifying full path to the “ProcessMDAN” . You typically want the first argument to be the process name, this is mentioned in the documentation.
and the thread_mdan:
void* thread_mdan(void *argc, char *argv[]) { … }
these are the shown errors:
initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* ()(void), void*)’
invalid conversion from ‘void* ()(void, char**)’ to ‘void* ()(void)’
if I change the thread to:
void* thread_mdan(void *argc){ …}
it works, but I have to use the “argv[]”… so, any idea?
Read the documentation, thread can only be passed a pointer, there is no way you can change this.
You call it *argc, but it’s not, it’s just a pointer and you get to decide what it points to. If you want to send argv you have to send the address of argv, that can be done with some casting.
I don’t know… I’m just adapting an existing program from qnx4 to QNX6…
I guess is the identification of the main… but I’m think that is not in use…
the verbose is used…