Skip to contentSkip to conversation

Synchronization between two processes

PATCH In review Gui Xiaohua 4 participants 10 messages May 15, 2009 – May 26, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Synchronization between two processes

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process. I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

kernel/containers/pidns/pidns12.c renamed from kernel/containers/pidns/pidns12-old.c +4 -1
@@ -109,7 +109,7 @@ int child_fn(void *arg)
 	}
 
 	/* Set timeout for sigtimedwait */
-	timeout.tv_sec = 3;
+	timeout.tv_sec = 10;
 	timeout.tv_nsec = 0;
 
 	/* Set mask to wait for SIGUSR1 signal */
@@ -182,6 +182,9 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
+	/*Try best to make sure the SIGUSR1 be sended after child-process execute sigtimedwait*/
+	sleep(5);
+
 	/* Send SIGUSR1 to container init */
 	if (kill(cpid, SIGUSR1) == -1) {
 		tst_resm(TBROK, "parent: kill() failed(%s).", strerror(errno));

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#1 lore raw
Quoted 7 lines · Gui Xiaohua

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process. I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

Over to Serge.

Regards--
Subrata

Quoted 25 lines
kernel/containers/pidns/pidns12.c renamed from kernel/containers/pidns/pidns12-old.c +4 -2
@@ -109,7 +109,7 @@ int child_fn(void *arg)
 	}
 
 	/* Set timeout for sigtimedwait */
-	timeout.tv_sec = 3;
+	timeout.tv_sec = 10;
 	timeout.tv_nsec = 0;
 
 	/* Set mask to wait for SIGUSR1 signal */
@@ -182,6 +182,9 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
+	/*Try best to make sure the SIGUSR1 be sended after child-process execute sigtimedwait*/
+	sleep(5);
+
 	/* Send SIGUSR1 to container init */
 	if (kill(cpid, SIGUSR1) == -1) {
 		tst_resm(TBROK, "parent: kill() failed(%s).", strerror(errno));
 
 
------------------------------------------------------------------------------

Crystal Reports - New Free Runtime and 30 Day Trial

Quoted 8 lines

Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw
In reply to Gui Xiaohua
Quoted 5 lines · Gui Xiaohua

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process. I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

Well, in theory I suppose this could happen, but you'd have to have a pretty bad scheduler if the parent can do a strcmp(buf, "c:go") between the pipe read and signal send, while the child goes straight from pipe write to sigtimedwait.

Have you seen this signal be missed? If not, then I'd rather assume things are reasonable. If you have seen this happen, then why not instead set up a SIGUSR1 handler in the child before doing the pipe write, then just sleep for 3 seconds instead of doing sigtimedwait?

Quoted 26 lines
kernel/containers/pidns/pidns12.c renamed from kernel/containers/pidns/pidns12-old.c +4 -2
@@ -109,7 +109,7 @@ int child_fn(void *arg)
 	}
 
 	/* Set timeout for sigtimedwait */
-	timeout.tv_sec = 3;
+	timeout.tv_sec = 10;
 	timeout.tv_nsec = 0;
 
 	/* Set mask to wait for SIGUSR1 signal */
@@ -182,6 +182,9 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
+	/*Try best to make sure the SIGUSR1 be sended after child-process execute sigtimedwait*/
+	sleep(5);
+
 	/* Send SIGUSR1 to container init */
 	if (kill(cpid, SIGUSR1) == -1) {
 		tst_resm(TBROK, "parent: kill() failed(%s).", strerror(errno));
 
 
------------------------------------------------------------------------------

Crystal Reports - New Free Runtime and 30 Day Trial

Quoted 8 lines

Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw
Quoted 12 lines · Serge E. Hallyn
Quoted 5 lines · Gui Xiaohua

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process. I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

Well, in theory I suppose this could happen, but you'd have to have a pretty bad scheduler if the parent can do a strcmp(buf, "c:go") between the pipe read and signal send, while the child goes straight from pipe write to sigtimedwait.

Quoted 4 lines

Have you seen this signal be missed? If not, then I'd rather assume things are reasonable. If you have seen this happen, then why not instead set up a SIGUSR1 handler in the child before doing the pipe write, then just sleep for 3 seconds instead of doing sigtimedwait?

Thanks Serge.

Gui,

Are you planning any further patch(s) for this ?

Regards--
Subrata

Quoted 38 lines
Quoted 27 lines
kernel/containers/pidns/pidns12.c renamed from kernel/containers/pidns/pidns12-old.c +4 -2
@@ -109,7 +109,7 @@ int child_fn(void *arg)
 	}
 
 	/* Set timeout for sigtimedwait */
-	timeout.tv_sec = 3;
+	timeout.tv_sec = 10;
 	timeout.tv_nsec = 0;
 
 	/* Set mask to wait for SIGUSR1 signal */
@@ -182,6 +182,9 @@ int main(int argc, char *argv[])
 		cleanup();
 	}
 
+	/*Try best to make sure the SIGUSR1 be sended after child-process execute sigtimedwait*/
+	sleep(5);
+
 	/* Send SIGUSR1 to container init */
 	if (kill(cpid, SIGUSR1) == -1) {
 		tst_resm(TBROK, "parent: kill() failed(%s).", strerror(errno));
 
 
------------------------------------------------------------------------------

Crystal Reports - New Free Runtime and 30 Day Trial

Quoted 8 lines

Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial

Quoted 8 lines

Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw
Quoted 13 lines · Subrata Modak
Quoted 12 lines · Serge E. Hallyn
Quoted 5 lines · Gui Xiaohua

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process. I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

Well, in theory I suppose this could happen, but you'd have to have a pretty bad scheduler if the parent can do a strcmp(buf, "c:go") between the pipe read and signal send, while the child goes straight from pipe write to sigtimedwait.

Quoted 6 lines
Quoted 4 lines

Have you seen this signal be missed? If not, then I'd rather assume things are reasonable. If you have seen this happen, then why not instead set up a SIGUSR1 handler in the child before doing the pipe write, then just sleep for 3 seconds instead of doing sigtimedwait?

Thanks Serge.

Or, if I'm being unreasonable, then at least have the parent only wait for at most 1 second, and leave the child alone. Every every ltp test is going to hang for 5 seconds...

But I prefer setting the signal handler ahead of time.

Quoted 3 lines

Gui,

Are you planning any further patch(s) for this ?

thanks,
-serge

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#5 lore raw
Quoted 22 lines · Serge E. Hallyn
Quoted 20 lines · Subrata Modak
Quoted 18 lines · Serge E. Hallyn
Quoted 6 lines · Gui Xiaohua

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process. I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

Well, in theory I suppose this could happen, but you'd have to have a pretty bad scheduler if the parent can do a strcmp(buf, "c:go") between the pipe read and signal send, while the child goes straight from pipe write to sigtimedwait.

Have you seen this signal be missed? If not, then I'd rather assume things are reasonable. If you have seen this happen, then why not instead set up a SIGUSR1 handler in the child before doing the pipe write, then just sleep for 3 seconds instead of doing sigtimedwait?

Quoted 10 lines
Quoted 2 lines

Thanks Serge.

Or, if I'm being unreasonable, then at least have the parent only wait for at most 1 second, and leave the child alone. Every every ltp test is going to hang for 5 seconds...

But I prefer setting the signal handler ahead of time.

Sorry to relpy late.

As your last advice, i change the test case, and it work will.

[PATCH] fix sync problem between two processes of pidns12 test

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process.

This patch rewrite child_signal_handler() to handle to SIGUSR1 and instead sigtimedwait() with sleep for 3 seconds.

---
 testcases/kernel/containers/pidns/pidns12.c |   35 ++++++--------------------
 1 files changed, 8 insertions(+), 27 deletions(-)
testcases/kernel/containers/pidns/pidns12.c +8 -27
index f893021..9120e82 100644
@@ -72,8 +72,13 @@ void cleanup()
  */
 static void child_signal_handler(int sig, siginfo_t *si, void *unused)
 {
-	/* sigtimedwait() traps siginfo details, so this wont be called */
-	tst_resm(TWARN, "cinit: control should have not reached here!");
+	/* Recieved SIGUSR1. Check sender pid */
+	if (si->si_pid == 0)
+		tst_resm(TPASS, "cinit: signalling PID (from other namespace)"\
+				" is 0 as expected");
+	else
+		tst_resm(TFAIL, "cinit: signalling PID (from other namespace)"\
+				" is not 0, but %d.", si->si_pid);
 }
 
 /*
@@ -82,9 +87,6 @@ static void child_signal_handler(int sig, siginfo_t *si, void *unused)
 int child_fn(void *arg)
 {
 	struct sigaction sa;
-	sigset_t newset;
-	siginfo_t info;
-	struct timespec timeout;
 	pid_t pid, ppid;
 
 	/* Set process id and parent pid */
@@ -108,34 +110,13 @@ int child_fn(void *arg)
 		cleanup();
 	}
 
-	/* Set timeout for sigtimedwait */
-	timeout.tv_sec = 3;
-	timeout.tv_nsec = 0;
-
-	/* Set mask to wait for SIGUSR1 signal */
-	sigemptyset(&newset);
-	sigaddset(&newset, SIGUSR1);
-
 	/* Let parent to signal SIGUSR1 */
 	if (write(pipefd[1], "c:go\0", 5) != 5) {
 		tst_resm(TBROK, "cinit: pipe is broken to write");
 		cleanup();
 	}
 
-	/* Wait for SIGUSR1 */
-	if (sigtimedwait(&newset, &info, &timeout) != SIGUSR1) {
-		tst_resm(TBROK, "cinit: sigtimedwait() failed(%s).",
-				strerror(errno));
-		cleanup();
-	}
-
-	/* Recieved SIGUSR1. Check sender pid */
-	if (info.si_pid == 0)
-		tst_resm(TPASS, "cinit: signalling PID (from other namespace)"\
-				" is 0 as expected");
-	else
-		tst_resm(TFAIL, "cinit: signalling PID (from other namespace)"\
-				" is not 0, but %d.", info.si_pid);
+	sleep(3);
 
 	/* cleanup and exit */
 	close(pipefd[1]);
Signature · 15 lines
1.6.3




------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#6 lore raw
Quoted 39 lines · Wei Yongjun
Quoted 22 lines · Serge E. Hallyn
Quoted 20 lines · Subrata Modak
Quoted 18 lines · Serge E. Hallyn
Quoted 6 lines · Gui Xiaohua

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process. I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

Well, in theory I suppose this could happen, but you'd have to have a pretty bad scheduler if the parent can do a strcmp(buf, "c:go") between the pipe read and signal send, while the child goes straight from pipe write to sigtimedwait.

Have you seen this signal be missed? If not, then I'd rather assume things are reasonable. If you have seen this happen, then why not instead set up a SIGUSR1 handler in the child before doing the pipe write, then just sleep for 3 seconds instead of doing sigtimedwait?

Quoted 10 lines
Quoted 2 lines

Thanks Serge.

Or, if I'm being unreasonable, then at least have the parent only wait for at most 1 second, and leave the child alone. Every every ltp test is going to hang for 5 seconds...

But I prefer setting the signal handler ahead of time.

Sorry to relpy late.

As your last advice, i change the test case, and it work will.

[PATCH] fix sync problem between two processes of pidns12 test

Quoted 8 lines

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process.

This patch rewrite child_signal_handler() to handle to SIGUSR1 and instead sigtimedwait() with sleep for 3 seconds.

Serge,

Your view on this new solution ?

Regards--
Subrata

Quoted 60 lines
---
 testcases/kernel/containers/pidns/pidns12.c |   35 ++++++--------------------
 1 files changed, 8 insertions(+), 27 deletions(-)
testcases/kernel/containers/pidns/pidns12.c +7 -21
index f893021..9120e82 100644
@@ -72,8 +72,13 @@ void cleanup()
  */
 static void child_signal_handler(int sig, siginfo_t *si, void *unused)
 {
-	/* sigtimedwait() traps siginfo details, so this wont be called */
-	tst_resm(TWARN, "cinit: control should have not reached here!");
+	/* Recieved SIGUSR1. Check sender pid */
+	if (si->si_pid == 0)
+		tst_resm(TPASS, "cinit: signalling PID (from other namespace)"\
+				" is 0 as expected");
+	else
+		tst_resm(TFAIL, "cinit: signalling PID (from other namespace)"\
+				" is not 0, but %d.", si->si_pid);
 }
 
 /*
@@ -82,9 +87,6 @@ static void child_signal_handler(int sig, siginfo_t *si, void *unused)
 int child_fn(void *arg)
 {
 	struct sigaction sa;
-	sigset_t newset;
-	siginfo_t info;
-	struct timespec timeout;
 	pid_t pid, ppid;
 
 	/* Set process id and parent pid */
@@ -108,34 +110,13 @@ int child_fn(void *arg)
 		cleanup();
 	}
 
-	/* Set timeout for sigtimedwait */
-	timeout.tv_sec = 3;
-	timeout.tv_nsec = 0;
-
-	/* Set mask to wait for SIGUSR1 signal */
-	sigemptyset(&newset);
-	sigaddset(&newset, SIGUSR1);
-
 	/* Let parent to signal SIGUSR1 */
 	if (write(pipefd[1], "c:go\0", 5) != 5) {
 		tst_resm(TBROK, "cinit: pipe is broken to write");
 		cleanup();
 	}
 
-	/* Wait for SIGUSR1 */
-	if (sigtimedwait(&newset, &info, &timeout) != SIGUSR1) {
-		tst_resm(TBROK, "cinit: sigtimedwait() failed(%s).",
-				strerror(errno));
-		cleanup();
-	}
-
-	/* Recieved SIGUSR1. Check sender pid */

testcases/kernel/containers/pidns/pidns12.c int child_fn(void *arg) · line 122

Quoted 10 lines
testcases/kernel/containers/pidns/pidns12.c +1 -6
-	if (info.si_pid == 0)
-		tst_resm(TPASS, "cinit: signalling PID (from other namespace)"\
-				" is 0 as expected");
-	else
-		tst_resm(TFAIL, "cinit: signalling PID (from other namespace)"\
-				" is not 0, but %d.", info.si_pid);
+	sleep(3);
 
 	/* cleanup and exit */
 	close(pipefd[1]);

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#9 lore raw
In reply to Wei Yongjun
Quoted 37 lines · Wei Yongjun
Quoted 22 lines · Serge E. Hallyn
Quoted 20 lines · Subrata Modak
Quoted 19 lines · Serge E. Hallyn
Quoted 7 lines · Gui Xiaohua

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process.
I cann't make sure the SIGUSR1 be sended after child-process execute sigtimedwait() with 100 percent, and i try my best.

Well, in theory I suppose this could happen, but you'd have to have a pretty bad scheduler if the parent can do a strcmp(buf, "c:go") between the pipe read and signal send, while the child goes straight from pipe write to sigtimedwait.

Have you seen this signal be missed? If not, then I'd rather assume things are reasonable. If you have seen this happen, then why not instead set up a SIGUSR1 handler in the child before doing the pipe write, then just sleep for 3 seconds instead of doing sigtimedwait?

Quoted 10 lines
Quoted 2 lines

Thanks Serge.

Or, if I'm being unreasonable, then at least have the parent only wait for at most 1 second, and leave the child alone. Every every ltp test is going to hang for 5 seconds...

But I prefer setting the signal handler ahead of time.

Sorry to relpy late.

As your last advice, i change the test case, and it work will.

Quoted 8 lines

[PATCH] fix sync problem between two processes of pidns12 test

The child-process wait SIGUSR1 which would be sended by parent-process, if the child-process execute sigtimedwait() after parent-process send the signal, it would never receive the SIGUSR1 from parent-process.

This patch rewrite child_signal_handler() to handle to SIGUSR1 and instead sigtimedwait() with sleep for 3 seconds.

Thank you, this looks right.

I assume the reason it wasn't originally done this way, was out of a concern that the TPASS/TFAIL out of signal handler wouldn't count...

-serge

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#7 lore raw
In reply to Subrata Modak
Quoted 5 lines · Subrata Modak
Quoted 1 line

Serge,

Your view on this new solution ?

Oops, i forgot to officially note:

thanks,
-serge

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#8 lore raw
Quoted 10 lines · Serge E. Hallyn
Quoted 5 lines · Subrata Modak
Quoted 1 line

Serge,

Your view on this new solution ?

Oops, i forgot to officially note:

Thanks to both of you.

Regards--
Subrata

Quoted 3 lines

thanks,
-serge

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list