How to send integer with pipe between two processes!

前端 未结 4 1719
情深已故
情深已故 2021-02-05 12:12

I am trying to send an integer with pipe in a POSIX system but write() function is working for sending string or character data. Is there any way to send integer wi

4条回答
  •  北海茫月
    2021-02-05 12:28

    Below one works fine for writing to pipe and reading from pipe as:

    stop_daemon =123;
    res = write(cli_pipe_fd_wr, &stop_daemon, sizeof(stop_daemon));
    ....
    res = read(pipe_fd_rd, buffer, sizeof(int));
    memcpy(&stop_daemon,buffer,sizeof(int));
    printf("CLI process read from res:%d status:%d\n", res, stop_daemon);
    

    output:

    CLI process read from res:4 status:123
    

提交回复
热议问题