* C-c in guile @ 2017-01-21 11:55 Alex Vong 2017-01-21 14:53 ` Matt Wette ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Alex Vong @ 2017-01-21 11:55 UTC (permalink / raw) To: guile-user [-- Attachment #1: Type: text/plain, Size: 385 bytes --] Hello, When running the external program "yes" in shell, $ yes We can terminate the process by pressing C-c. However, when running the external program "yes" in guile, $ guile -c '(system* "yes")' We cannot terminate the process by pressing C-c, but we can suspend it by pressing C-z. Why is that? Is there any way I can terminate the process by pressing C-c? Thanks, Alex [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 832 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C-c in guile 2017-01-21 11:55 C-c in guile Alex Vong @ 2017-01-21 14:53 ` Matt Wette 2017-01-22 6:54 ` Alex Vong 2017-02-27 19:49 ` Andy Wingo 2017-05-15 17:46 ` Alex Vong 2 siblings, 1 reply; 7+ messages in thread From: Matt Wette @ 2017-01-21 14:53 UTC (permalink / raw) To: Alex Vong; +Cc: guile-user > On Jan 21, 2017, at 3:55 AM, Alex Vong <alexvong1995@gmail.com> wrote: > > Hello, > > When running the external program "yes" in shell, > > $ yes > > We can terminate the process by pressing C-c. > > However, when running the external program "yes" in guile, > > $ guile -c '(system* "yes")' > > We cannot terminate the process by pressing C-c, > but we can suspend it by pressing C-z. > > Why is that? Is there any way I can terminate the process by pressing > C-c? > > Thanks, > Alex C-c works on your guile example for me on my Mac. Try `C-\’. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C-c in guile 2017-01-21 14:53 ` Matt Wette @ 2017-01-22 6:54 ` Alex Vong 2017-01-23 16:05 ` Vladimir Zhbanov 0 siblings, 1 reply; 7+ messages in thread From: Alex Vong @ 2017-01-22 6:54 UTC (permalink / raw) To: Matt Wette; +Cc: guile-user [-- Attachment #1: Type: text/plain, Size: 883 bytes --] Matt Wette <matt.wette@gmail.com> writes: >> On Jan 21, 2017, at 3:55 AM, Alex Vong <alexvong1995@gmail.com> wrote: >> >> Hello, >> >> When running the external program "yes" in shell, >> >> $ yes >> >> We can terminate the process by pressing C-c. >> >> However, when running the external program "yes" in guile, >> >> $ guile -c '(system* "yes")' >> >> We cannot terminate the process by pressing C-c, >> but we can suspend it by pressing C-z. >> >> Why is that? Is there any way I can terminate the process by pressing >> C-c? >> >> Thanks, >> Alex > > C-c works on your guile example for me on my Mac. Try `C-\’. Hmmm... Neither does 'C-\' work on the guile example. It works on the shell example though. I am running Debian with 'uname -a' being: Linux debian 4.8.0-2-amd64 #1 SMP Debian 4.8.15-2 (2017-01-04) x86_64 GNU/Linux [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 832 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C-c in guile 2017-01-22 6:54 ` Alex Vong @ 2017-01-23 16:05 ` Vladimir Zhbanov 0 siblings, 0 replies; 7+ messages in thread From: Vladimir Zhbanov @ 2017-01-23 16:05 UTC (permalink / raw) To: guile-user On Sun, Jan 22, 2017 at 02:54:31PM +0800, Alex Vong wrote: > Matt Wette <matt.wette@gmail.com> writes: > > >> On Jan 21, 2017, at 3:55 AM, Alex Vong <alexvong1995@gmail.com> wrote: > >> > >> Hello, > >> > >> When running the external program "yes" in shell, > >> > >> $ yes > >> > >> We can terminate the process by pressing C-c. > >> > >> However, when running the external program "yes" in guile, > >> > >> $ guile -c '(system* "yes")' > >> > >> We cannot terminate the process by pressing C-c, > >> but we can suspend it by pressing C-z. > >> > >> Why is that? Is there any way I can terminate the process by pressing > >> C-c? > >> > >> Thanks, > >> Alex > > > > C-c works on your guile example for me on my Mac. Try `C-\’. > > Hmmm... Neither does 'C-\' work on the guile example. It works on the > shell example though. > > I am running Debian with 'uname -a' being: > Linux debian 4.8.0-2-amd64 #1 SMP Debian 4.8.15-2 (2017-01-04) x86_64 GNU/Linux I see the same having a bit older debian and guile 2.0.11. Some experiments have shown that in such a case `guile' and `yes' do not react to SIGINT (which IIUC C-c produces) while handle SIGTERM correctly. -- Vladimir ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C-c in guile 2017-01-21 11:55 C-c in guile Alex Vong 2017-01-21 14:53 ` Matt Wette @ 2017-02-27 19:49 ` Andy Wingo 2017-03-01 16:03 ` Alex Vong 2017-05-15 17:46 ` Alex Vong 2 siblings, 1 reply; 7+ messages in thread From: Andy Wingo @ 2017-02-27 19:49 UTC (permalink / raw) To: Alex Vong; +Cc: guile-user On Sat 21 Jan 2017 12:55, Alex Vong <alexvong1995@gmail.com> writes: > However, when running the external program "yes" in guile, > > $ guile -c '(system* "yes")' > > We cannot terminate the process by pressing C-c, Indeed I can reproduce this! > but we can suspend it by pressing C-z. I believe the C-z is handled by the shell, not Guile; AFAIU. I don't know how this should work (mechanics) but I agree with you that probably it should! Andy ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C-c in guile 2017-02-27 19:49 ` Andy Wingo @ 2017-03-01 16:03 ` Alex Vong 0 siblings, 0 replies; 7+ messages in thread From: Alex Vong @ 2017-03-01 16:03 UTC (permalink / raw) To: Andy Wingo; +Cc: guile-user [-- Attachment #1: Type: text/plain, Size: 689 bytes --] Andy Wingo <wingo@pobox.com> writes: > On Sat 21 Jan 2017 12:55, Alex Vong <alexvong1995@gmail.com> writes: > >> However, when running the external program "yes" in guile, >> >> $ guile -c '(system* "yes")' >> >> We cannot terminate the process by pressing C-c, > > Indeed I can reproduce this! > >> but we can suspend it by pressing C-z. > > I believe the C-z is handled by the shell, not Guile; AFAIU. > > I don't know how this should work (mechanics) but I agree with you that > probably it should! > I've just checked, a python equivalence of the above command works: $ python -c 'import subprocess; subprocess.call("yes")' Maybe some ideas can be extracted from it. > Andy [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 832 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: C-c in guile 2017-01-21 11:55 C-c in guile Alex Vong 2017-01-21 14:53 ` Matt Wette 2017-02-27 19:49 ` Andy Wingo @ 2017-05-15 17:46 ` Alex Vong 2 siblings, 0 replies; 7+ messages in thread From: Alex Vong @ 2017-05-15 17:46 UTC (permalink / raw) To: guile-user [-- Attachment #1.1: Type: text/plain, Size: 1218 bytes --] Hello, I manage to find a solution: define a new procedure 'system**' which is implemented in C using fork-exec-waitpid. The code is in the attchment. To compile the C extension, run: $ gcc -o libguile-system_star_star.so -shared -fPIC \ `pkg-config --cflags guile-2.2` -O2 -Wall -Wextra system_star_star.c To test the C extension, try running something like: (use-modules (ice-9 threads)) (load-extension "./libguile-system_star_star" "init_system_star_star") (define n 10000) (define s (make-string n #\s)) (define l (make-list n s)) (define main (lambda _ (parallel (system** "echo" "foo" "bar") (apply system** l) (system** "echo" "foo" "bar") (apply system** l)))) C-c should terminate the program. My first solution was to use 'primitive-fork'. But it didn't work, because guile warned me that 'primitive-fork' shouldn't be called in a multithreaded program. I want to find out why. So I read the man-page and it says after forking in a multithread program, it is only safe to call async-safe functions. So I re-implement the whole thing in C and exec right after forking. This is how I come up with the current solution. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1.2: system_star_star.c --] [-- Type: text/x-csrc, Size: 1871 bytes --] /* Copyright (C) 2017 Alex Vong <alexvong1995@gmail.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 3 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA */ #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <libguile.h> static SCM system_star_star(SCM prog, SCM args) { SCM prog_args = scm_cons(prog, args); size_t len = scm_to_size_t(scm_length(prog_args)); char **argv = scm_gc_malloc((len + 1) * sizeof(char *), "argv"); for (size_t k = 0; k < len; ++k) { SCM arg = SCM_CAR(prog_args); size_t len = scm_c_string_length(arg); argv[k] = scm_gc_malloc_pointerless(len + 1, "argv[k]"); scm_to_locale_stringbuf(arg, argv[k], len); argv[k][len] = '\0'; prog_args = SCM_CDR(prog_args); } argv[len] = NULL; int status = 0; pid_t pid = fork(); if (pid == -1) scm_syserror("system**"); if (pid == 0) /* child */ { execvp(argv[0], argv); _exit(127); } else /* parent */ { if (waitpid(pid, &status, 0) == -1) scm_syserror("system**"); } return scm_from_int(status); } void init_system_star_star(void) { scm_c_define_gsubr("system**", 1, 0, 1, system_star_star); } [-- Attachment #1.3: Type: text/plain, Size: 478 bytes --] Cheers, Alex Alex Vong <alexvong1995@gmail.com> writes: > Hello, > > When running the external program "yes" in shell, > > $ yes > > We can terminate the process by pressing C-c. > > However, when running the external program "yes" in guile, > > $ guile -c '(system* "yes")' > > We cannot terminate the process by pressing C-c, > but we can suspend it by pressing C-z. > > Why is that? Is there any way I can terminate the process by pressing > C-c? > > Thanks, > Alex [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 832 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-05-15 17:46 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-01-21 11:55 C-c in guile Alex Vong 2017-01-21 14:53 ` Matt Wette 2017-01-22 6:54 ` Alex Vong 2017-01-23 16:05 ` Vladimir Zhbanov 2017-02-27 19:49 ` Andy Wingo 2017-03-01 16:03 ` Alex Vong 2017-05-15 17:46 ` Alex Vong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).