Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MSGC "Mesaj copil"
- #define MSGP "Mesaj parinte"
- void login() {
- pid_t childPID = fork();
- int sockp[2];
- static const int ps = 0; // parent socker
- static const int cs = 1; // child socket
- char usr[64], psd[64];
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockp) < 0) {
- perror("Err... socketpair");
- exit(1);
- }
- if(childPID < 0){
- perror("Nu pot fork()\n");
- exit(1);
- }
- else if(childPID == 0) { // Copil
- if (read(sockp[cs], usr, sizeof(usr)) < 0) perror("[C] Error read(): ");
- printf("Procesul cu PID %d (c) a primit '%s'\n", getpid(), usr);
- if (write(sockp[cs], MSGC, sizeof(MSGC)) < 0) perror("[C] Error write(): ");
- close(sockp[cs]);
- }
- else { // Parinte
- if(write(sockp[ps], MSGP, sizeof(MSGP)) < 0) perror("[P]Error: write()");
- if(read(sockp[ps], usr, 64) < 0) perror("[P] Error read(): ");
- printf("Procesul cu PID %d(p) a primit %s\n", getpid(), usr);
- close(sockp[ps]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement