Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <sys/neutrino.h>
- #include <process.h>
- #include <ctype.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sched.h>
- #include <process.h>
- #include <sys/wait.h>
- #include <sys/iomsg.h>
- #define PR_POTOMNY "./klient"
- #define SIZE 256
- typedef struct {
- int typ; // Typ komunikatu
- int od; // Numer procesu
- char tekst[SIZE]; // Tekst komunikatu
- } kom_t;
- int main(int argc, char* argv[]) {
- int chid, pid, rcvid;
- int status;
- kom_t msg;
- int il_proc_potomnych = atoi(argv[1]);
- chid = ChannelCreate(0);
- pid = getpid();
- printf("Server's pid: %d, chid: %d\n", pid, chid);
- int i = 0;
- for(i = 0; i < il_proc_potomnych; i++) {
- int pr_potomny_pid = fork();
- if (!pr_potomny_pid) {
- char pid_chars[20];
- char chid_chars[20];
- int base = 10;
- itoa(pid, pid_chars, base);
- itoa(chid, chid_chars, base);
- execl (PR_POTOMNY, PR_POTOMNY, pid_chars, chid_chars, (char *)NULL);
- }
- }
- while(1) {
- rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
- if(msg.typ == 0) {
- printf("\t Proces %d wyslal zakonczenie\n", msg.od);
- status = MsgReply(rcvid, EOK, &msg, sizeof(msg) );
- il_proc_potomnych--;
- if(il_proc_potomnych == 0) {
- break;
- }
- continue;
- }
- printf("%s", msg.tekst);
- msg.od = getpid();
- msg.typ = 1;
- status = MsgReply(rcvid, EOK, &msg, sizeof(msg) );
- }
- printf("po petli\n");
- while((pid=wait(&status))!=-1) {
- printf("Proces %d zakonczony, status %d\n",pid,WEXITSTATUS(status));
- }
- return 0;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/neutrino.h>
- #include <sys/netmgr.h>
- #include <process.h>
- #include <sys/wait.h>
- #include <sys/iomsg.h>
- #define SIZE 256
- typedef struct {
- int typ; // Typ komunikatu
- int od; // Numer procesu
- char tekst[SIZE]; // Tekst komunikatu
- } kom_t;
- int main(int argc, char* argv[])
- {
- int coid, server_pid, server_chid;
- kom_t msg;
- kom_t reply;
- if(argc != 3) {
- printf("Server Pid\n");
- printf("Server Chid\n");
- exit(EXIT_FAILURE);
- }
- server_pid = atoi(argv[1]);
- server_chid = atoi(argv[2]);
- printf("Server pid: %d, chid %d\n", server_pid, server_chid);
- coid = ConnectAttach(ND_LOCAL_NODE, server_pid, server_chid, _NTO_SIDE_CHANNEL, 0);
- int i = 0;
- while(i++ < 10) {
- msg.typ = 1;
- msg.od = getpid();
- sprintf(msg.tekst, "Proces %d, krok petli %d\n", getpid(), i);
- MsgSend(coid, &msg, sizeof(msg), &reply, sizeof(reply) );
- sleep(1);
- }
- msg.typ = 0;
- MsgSend(coid, &msg, sizeof(msg), &reply, sizeof(reply) );
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement