dlugolecki.net.pl
Dziennik
Polecane
Software
projects
/
wsti_so.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Turn On/Off pids on notifying other processes.
[wsti_so.git]
/
src
/
process1.c
diff --git
a/src/process1.c
b/src/process1.c
index fbbfa40c1b2d5f848ea279ce4ce954b106719062..69e6bda8ab4d0189e491aeb87b817769e83ce72c 100644
(file)
--- a/
src/process1.c
+++ b/
src/process1.c
@@
-48,11
+48,24
@@
struct message {
struct message * processes = NULL;
/**
struct message * processes = NULL;
/**
- * Message queue variables
+ * Message Queue variables
+ */
+
+/**
+ * Unique key of message queue.
*/
key_t qkey = 12356;
*/
key_t qkey = 12356;
+
+/**
+ * Queue descriptor.
+ */
int qid;
int qid;
+/**
+ * Structure holding queue message data.
+ * Parameter mtype describes process to whom message is sent.
+ * Parameter signo is a signal to raise after getting message.
+ */
struct queue_message {
long mtype;
int signo[1];
struct queue_message {
long mtype;
int signo[1];
@@
-82,7
+95,6
@@
void notify_other_processes(int signo) {
void sig_handler(int signo)
{
fprintf(stderr, "[%s] Received %s!\n", "process1", strsignal(signo));
void sig_handler(int signo)
{
fprintf(stderr, "[%s] Received %s!\n", "process1", strsignal(signo));
-
if (signo == SIGUSR1) {
fprintf(stderr, "[%s] > Notified!\n", "process1");
struct queue_message msg;
if (signo == SIGUSR1) {
fprintf(stderr, "[%s] > Notified!\n", "process1");
struct queue_message msg;
@@
-91,14
+103,10
@@
void sig_handler(int signo)
fprintf(stderr, "[%s] > Notified with value: %s!\n", "process1", strsignal(msg.signo[0]));
raise(msg.signo[0]);
}
fprintf(stderr, "[%s] > Notified with value: %s!\n", "process1", strsignal(msg.signo[0]));
raise(msg.signo[0]);
}
- else if (msgrcv(qid, &msg, sizeof(int), 1, 0) > 0) {
- fprintf(stderr, "[%s] > Notified with value: %s!\n", "process1", strsignal(msg.signo[0]));
- raise(msg.signo[0]);
- }
}
else if (signo == SIGTERM) {
fprintf(stderr, "[%s] > Signalling other processes..\n", "process1");
}
else if (signo == SIGTERM) {
fprintf(stderr, "[%s] > Signalling other processes..\n", "process1");
- processes->pids[
1
] = 0;
+ processes->pids[
0
] = 0;
notify_other_processes(signo);
fprintf(stderr, "[%s] > Releasing resources\n", "process1");
notify_other_processes(signo);
fprintf(stderr, "[%s] > Releasing resources\n", "process1");
@@
-112,6
+120,12
@@
void sig_handler(int signo)
exit(0);
}
else if (signo == SIGTSTP) {
exit(0);
}
else if (signo == SIGTSTP) {
+ fprintf(stderr, "[%s] > Signalling other processes..\n", "process1");
+ processes->pids[0] = 0;
+ notify_other_processes(signo);
+// sleep(1);
+ processes->pids[0] = getpid();
+
fprintf(stderr, "[%s] > Closing pipe\n", "process1");
close(write_pipe);
raise (SIGSTOP);
fprintf(stderr, "[%s] > Closing pipe\n", "process1");
close(write_pipe);
raise (SIGSTOP);
@@
-119,6
+133,10
@@
void sig_handler(int signo)
else if (signo == SIGCONT) {
fprintf(stderr, "[%s] > Opening pipe\n", "process1");
file_descriptor = open(write_pipe, O_WRONLY);
else if (signo == SIGCONT) {
fprintf(stderr, "[%s] > Opening pipe\n", "process1");
file_descriptor = open(write_pipe, O_WRONLY);
+ processes->pids[0] = 0;
+ notify_other_processes(signo);
+// sleep(1);
+ processes->pids[0] = getpid();
}
}
}
}