Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- komunikaty
- 2 procesy
- program ma tr\worzyc 2 procesy komunikujace sie za pomoca mechanixzmu komunikatow. proces serwer(odbioraca)
- musi utworzyc kanal polaczeniowy, a klient musi sie do niego podlaczyc i wtedy przeslac komunikat,
- wazne jest aby role podczas procesu sie nie zmienialy
- 2 procesy w 1 programie(procesy potomne)
- funkcja fork(rozwidlanie procesow).
- help: tam gdzie sygnaly tylko duzo wczesniej.
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/neutrino.h>
- #include <errno.h>
- #include <process.h>
- int main(int argc, char *argv[])
- {
- int connection_id = 0;
- int rcvid = 0;
- char Incommingbuffer[500];
- struct _pulse * p;
- struct _msg_info info;
- // create channel
- if ( (connection_id = ChannelCreate(_NTO_CHF_DISCONNECT )) == -1)
- {
- printf("Nie udaol sie stworzy kanau\n");
- return 0;
- }
- printf("Connection id is %d\n", connection_id);
- printf("Process id is %d\n", getpid() );
- for ( ; ; )
- {
- memset(Incommingbuffer, '\0',sizeof(info));
- rcvid = MsgReceive(connection_id, Incommingbuffer, sizeof(info), &info);
- printf("rcvid id %d \n", rcvid);
- printf("Message is %s \n", Incommingbuffer);
- if (rcvid == 0 )
- {
- // got a pulse indicating logger died
- p = (void *)Incommingbuffer;
- if (p->code == _PULSE_CODE_DISCONNECT )
- {
- printf("Detected that the logger process died\n");
- exit(-1);
- }
- }
- else
- {
- MsgReply(rcvid, EOK, NULL, 0);
- }
- }
- return EXIT_SUCCESS;
- }
- -------------------------------------------------------------------- 1 ----------------------------------------------
- #include <stdlib.h>
- #include <stdio.h>
- #include <pthread.h>
- #include <time.h>
- #define uint unsigned int
- void* thread1(void* );
- void* thread2(void* );
- sigset_t set;
- int main(int argc, char *argv[]) {
- pthread_t thrd1;
- pthread_t thrd2;
- sigemptyset( &set );
- sigaddset( &set, 41 );
- sigaddset( &set, 42 );
- pthread_create(&thrd1,NULL,thread1,NULL);
- pthread_create(&thrd2,NULL,thread2,NULL);
- fflush(stdout);
- while(1){}
- return EXIT_SUCCESS;
- }
- void* thread1(void* not_used) {
- extern void handler1();
- struct sigaction action1;
- sigset_t set;
- //siginfo_t info;
- action1.sa_flags = 0;
- action1.sa_mask = set;
- action1.sa_handler = &handler1;
- //sigaddset( &set, SIGUSR1 );
- sigaction( 41, &action1, NULL );
- //sigwaitinfo(&set, &info);
- return NULL;
- }
- void* thread2(void* not_used) {
- extern void handler2();
- struct sigaction action2;
- sigset_t set;
- // siginfo_t info;
- action2.sa_flags = 0;
- action2.sa_mask = set;
- action2.sa_handler = &handler2;
- sigaction( 42, &action2, NULL );
- return NULL;
- }
- void handler1( signo ) {
- printf("Otrzymano sygnal 1");
- fflush(stdout);
- }
- void handler2( signo ) {
- printf("Otrzymano sygnal 2");
- fflush(stdout);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement