Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to create two different processes
Qt 6.11 is out! See what's new in the release blog

How to create two different processes

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janaki
    wrote on last edited by
    #1

    hello sir,
    i was asked to create two different process where in one process, main function should be there which should have abstract calls as follows:-
    port = initialize_port(PORT _TYPE) ;
    writeport = (port,buf,size,PORT_TYPE);
    readport =(port,buf,size,PORT_TYPE);
    closeport();
    and in other process qt gui should be there

    may i get any suggestion how to do this

    please help me this is a bit urgent

    thanking u

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      You can start "here":http://qt-project.org/doc/qt-5.0/qtcore/qprocess.html#details


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        janaki
        wrote on last edited by
        #3

        thank u sir
        but i should not use qt related calls for creating the process it should be in C++
        can u please guide me
        thanking u sir

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Das
          wrote on last edited by
          #4

          For that you need platform specific call, imo.

          If you are on linux, have a look at "this pdf":http://www.advancedlinuxprogramming.com/alp-folder/alp-ch03-processes.pdf (abt fork, exec etc)


          Declaration of (Platform) independence.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            janaki
            wrote on last edited by
            #5

            #include<iostream>
            #include <stdio.h>
            #include <stdlib.h>
            #include <pthread.h>
            #include "structures.h"
            #include <string.h>
            #include <unistd.h>
            #include <stdio.h>
            #include <sys/socket.h>
            #include <netinet/in.h>
            #include <sys/types.h>
            #include <arpa/inet.h>

            #include <fcntl.h>
            #include <signal.h>

            #define MAX_DATA_SIZE 512
            #define ID

            using namespace std;

            struct Message
            {
            int message_id;
            }msg;

            void received_data(void);

            int main()
            {
            cout<<"main program"<<endl;

            pthread_t thread1,thread2;
            int status,status2;

            status= pthread_create(&thread1,NULL,received_data,NULL);
            status2 = pthread_create(&thread2,NULL,process,NULL);
            pthread_join(thread1,NULL);
            if(status<0)
            {
            perror("pthread_create failed");
            exit(0);
            }

            sleep(1);

            status = pthread_join(thread1,NULL);

            exit (0);
            }

            void *received_data(void *)
            {
            std::cerr<<"am in thread"<<std::endl;
            Message msg;
            printf("Hello\n");
            int fd;
            sigset_t set;
            printf("Hello2\n");
            struct sockaddr_in servaddr, cliaddr;

            void **status;

            fd = socket(AF_INET,SOCK_DGRAM,0);
            printf("Hello3\n");

            if(fd <0)
            cout<<"Socket creation Failed"<<endl;

            servaddr.sin_family = AF_INET;
            servaddr.sin_addr.s_addr = inet_addr("10.66.48.11"); //server ip addr
            // servaddr.sin_addr.s_addr = inet_addr("10.66.48.23"); //server ip addr
            servaddr.sin_port = htons(12005); //server poet no.
            printf("Hello4\n");
            if(bind(fd,(const struct sockaddr *)&servaddr,sizeof(servaddr))<0)
            cout<<"BIND FAILED"<<endl;
            unsigned char buffer[MAX_DATA_SIZE];

            socklen_t len=sizeof(cliaddr);
            fcntl(fd,F_SETFL,O_NONBLOCK);

            printf("Hello5\n");

            for(;;)
            {
            sleep(3);
            int n= recvfrom(fd,buffer,sizeof(buffer),0,(struct sockaddr *)&cliaddr,&len);

                        memcpy(&msg,buffer,sizeof(msg));
            

            printf("Hello7\n");
            cout<<"Received : bytes"<<n<<" "<<msg.message_id<<endl;

            }

            pthread_exit(0);

            }

            i shud have 4 threads in my main program

            1. received_data - first threads receive messages
            2. process_data - whenever a message is received in first thread a signal should be sent to second thread for processing data - message id received from first thread should be used for processing data
            3. health_data - this thread sends health message for every 20 seconds
            4. display_data - this thread should display status in the gui.

            i have written first thread which is working successfully, but am not getting idea how to send a signal when message is received and how to attach a signal handler when signal is received with the function in the second thread.
            kindly suggest me for doing this

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved