* jobs -Z example? @ 2009-03-15 18:24 Atom Smasher 2009-03-15 19:47 ` Bart Schaefer 0 siblings, 1 reply; 11+ messages in thread From: Atom Smasher @ 2009-03-15 18:24 UTC (permalink / raw) To: zsh-users can someone point me to an example of "jobs -Z" in action? thanks... -- ...atom ________________________ http://atom.smasher.org/ 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808 ------------------------------------------------- "Every successful revolt is termed a revolution, and every unsuccessful one a rebellion." -- Joseph Priestly, 1791 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 18:24 jobs -Z example? Atom Smasher @ 2009-03-15 19:47 ` Bart Schaefer 2009-03-15 20:49 ` Atom Smasher 0 siblings, 1 reply; 11+ messages in thread From: Bart Schaefer @ 2009-03-15 19:47 UTC (permalink / raw) To: zsh-users On Mar 16, 7:24am, Atom Smasher wrote: } } can someone point me to an example of "jobs -Z" in action? torch% ps $$ PID TTY STAT TIME COMMAND 5249 pts/4 Ss 0:00 Src/zsh -f torch% jobs -Z "You can't see me" torch% ps $$ PID TTY STAT TIME COMMAND 5249 pts/4 Ss 0:00 You can't see me torch% print $(< /proc/$$/cmdline ) You can't see me torch% If you mean an explanation of why you'd *want* to do that sort of thing, the reasons can be a bit obscure. As one real-world example, at work we run a job queuing system where a controller process passes tasks to a set of worker processes. The worker processes are each a subshell of a "foreman" script which runs in an infinite loop to keep track of how many workers are active and to start a new one when one exits. So the script at startup runs something like jobs -Z "worker:foreman" and when each subshell starts it runs jobs -Z "worker:task" That way, we can differentiate in "ps" output which process is which, rather than having them all appear to be copies of the same script. If we want to shut the system down cleanly, we kill the foreman and let the workers die off as their tasks complete. Yes, we could do this by having the foreman write it's PID to a file instead, etc. This just makes it obvious when running "top" or other system monitoring. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 19:47 ` Bart Schaefer @ 2009-03-15 20:49 ` Atom Smasher 2009-03-15 21:05 ` Christian Schneider 2009-03-15 21:07 ` Bart Schaefer 0 siblings, 2 replies; 11+ messages in thread From: Atom Smasher @ 2009-03-15 20:49 UTC (permalink / raw) To: zsh-users On Sun, 15 Mar 2009, Bart Schaefer wrote: > } can someone point me to an example of "jobs -Z" in action? > > torch% ps $$ > PID TTY STAT TIME COMMAND > 5249 pts/4 Ss 0:00 Src/zsh -f > torch% jobs -Z "You can't see me" > torch% ps $$ > PID TTY STAT TIME COMMAND > 5249 pts/4 Ss 0:00 You can't see me > torch% print $(< /proc/$$/cmdline ) > You can't see me > torch% ===================== that's pretty much what i expected, but it's not working on freeBSD. 7.1-STABLE + zsh 4.3.9 (amd64-portbld-freebsd7.1) 6.2-RELEASE + zsh 4.3.6 (amd64-portbld-freebsd6.2) maybe it's a freeBSD/amd64 thing? it seems to work fine on linux (P3). -- ...atom ________________________ http://atom.smasher.org/ 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808 ------------------------------------------------- "Whenever people say 'We mustn't be sentimental', you can take it they are about to do something cruel. And if they add 'We must be realistic', they mean they are going to make money out of it." -- Brigid Brophy ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 20:49 ` Atom Smasher @ 2009-03-15 21:05 ` Christian Schneider 2009-03-15 21:07 ` Bart Schaefer 1 sibling, 0 replies; 11+ messages in thread From: Christian Schneider @ 2009-03-15 21:05 UTC (permalink / raw) To: zsh-users Thus spake Atom Smasher (atom@smasher.org): > On Sun, 15 Mar 2009, Bart Schaefer wrote: >> } can someone point me to an example of "jobs -Z" in action? >> >> torch% ps $$ >> PID TTY STAT TIME COMMAND >> 5249 pts/4 Ss 0:00 Src/zsh -f >> torch% jobs -Z "You can't see me" >> torch% ps $$ >> PID TTY STAT TIME COMMAND >> 5249 pts/4 Ss 0:00 You can't see me >> torch% print $(< /proc/$$/cmdline ) >> You can't see me >> torch% > ===================== > > that's pretty much what i expected, but it's not working on freeBSD. > > 7.1-STABLE + zsh 4.3.9 (amd64-portbld-freebsd7.1) > 6.2-RELEASE + zsh 4.3.6 (amd64-portbld-freebsd6.2) > > maybe it's a freeBSD/amd64 thing? it seems to work fine on linux (P3). Works fine on Linux 2.6.26 and OpenBSD 4.4 (both i386) #v+ (dope@dreckskind) : (~): zsh --version zsh 4.3.6 (i386-unknown-openbsd4.4) (dope@dreckskind) : (~): jobs -Z "You can't see me" (dope@dreckskind) : (~): ps $$ PID TT STAT TIME COMMAND 29389 p0 Ss 0:00.32 You can't see me (zsh) (dope@dreckskind) : (~): #v- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 20:49 ` Atom Smasher 2009-03-15 21:05 ` Christian Schneider @ 2009-03-15 21:07 ` Bart Schaefer 2009-03-15 21:41 ` Atom Smasher 1 sibling, 1 reply; 11+ messages in thread From: Bart Schaefer @ 2009-03-15 21:07 UTC (permalink / raw) To: zsh-users On Mar 16, 9:49am, Atom Smasher wrote: } } that's pretty much what i expected, but it's not working on freeBSD. Some OSs stash the original command and environment so that you can't conceal them this way, because malware sometimes attempts to disguise itself with this trick so it's considered more secure to disallow it. Try this: perl -e '$0 = "Test hiding command"; sleep 10;' & ps $! If perl is able to do it but zsh is not, then it's just that FreeBSD has a different mechanism for it and we may be able to patch zsh. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 21:07 ` Bart Schaefer @ 2009-03-15 21:41 ` Atom Smasher 2009-03-15 22:08 ` Bart Schaefer 0 siblings, 1 reply; 11+ messages in thread From: Atom Smasher @ 2009-03-15 21:41 UTC (permalink / raw) To: zsh-users On Sun, 15 Mar 2009, Bart Schaefer wrote: > Some OSs stash the original command and environment so that you can't > conceal them this way, because malware sometimes attempts to disguise > itself with this trick so it's considered more secure to disallow it. > > Try this: > > perl -e '$0 = "Test hiding command"; sleep 10;' & ps $! > > If perl is able to do it but zsh is not, then it's just that FreeBSD has > a different mechanism for it and we may be able to patch zsh. ===================== weird.... (FreeBSD 6.2-RELEASE amd64) it sometimes works under bash, doesn't work under zsh. see below. similar results in a 7.1-STABLE jail, but it seems more likely to work as desired. * bash: for n in {1..10}; do perl -e '$0 = "Test hiding command"; sleep 10;' & done ; ps -t p7 [1] 5247 [2] 5248 [3] 5249 [4] 5250 [5] 5251 [6] 5252 [7] 5253 [8] 5254 [9] 5255 [10] 5256 PID TT STAT TIME COMMAND 945 p7 Is 0:00.87 zsh 4843 p7 S 0:00.15 bash 5247 p7 S 0:00.01 Test hiding command (perl5.8.8) 5248 p7 S 0:00.01 Test hiding command (perl5.8.8) 5249 p7 S 0:00.01 Test hiding command (perl5.8.8) 5250 p7 S 0:00.01 Test hiding command (perl5.8.8) 5251 p7 R 0:00.00 perl -e $0 = "Test hiding command"; sleep 10; (perl5.8.8) 5252 p7 S 0:00.01 Test hiding command (perl5.8.8) 5253 p7 RL 0:00.00 perl -e $0 = "Test hiding command"; sleep 10; (perl5.8.8) 5254 p7 R 0:00.00 perl -e $0 = "Test hiding command"; sleep 10; (perl5.8.8) 5255 p7 S 0:00.01 Test hiding command (perl5.8.8) 5256 p7 D 0:00.00 perl -e $0 = "Test hiding command"; sleep 10; (perl5.8.8) 5257 p7 R+ 0:00.00 ps -t p7 * zsh: for n in {1..10}; do perl -e '$0 = "Test hiding command"; sleep 10;' & done ; ps -t p7 [2] 5341 [3] 5342 [4] 5343 [5] 5344 [6] 5345 [7] 5346 [8] 5347 [9] 5348 [10] 5349 [11] 5350 PID TT STAT TIME COMMAND 945 p7 Ss 0:01.00 zsh 5341 p7 RN 0:00.00 zsh 5342 p7 RNL 0:00.00 zsh 5343 p7 DN 0:00.00 zsh 5344 p7 DN 0:00.00 zsh 5345 p7 DN 0:00.00 zsh 5346 p7 DN 0:00.00 zsh 5347 p7 DN 0:00.00 zsh 5348 p7 DN 0:00.00 zsh 5349 p7 DN 0:00.00 zsh 5350 p7 DN 0:00.00 zsh 5351 p7 R+ 0:00.00 ps -t p7 -- ...atom ________________________ http://atom.smasher.org/ 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808 ------------------------------------------------- To become vegetarian is to step into the stream which leads to nirvana. -- Buddha ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 21:41 ` Atom Smasher @ 2009-03-15 22:08 ` Bart Schaefer 2009-03-15 22:13 ` Atom Smasher 0 siblings, 1 reply; 11+ messages in thread From: Bart Schaefer @ 2009-03-15 22:08 UTC (permalink / raw) To: zsh-users On Mar 16, 10:41am, Atom Smasher wrote: } } On Sun, 15 Mar 2009, Bart Schaefer wrote: } } > Try this: } > } > perl -e '$0 = "Test hiding command"; sleep 10;' & ps $! } > } > If perl is able to do it but zsh is not, then it's just that FreeBSD has } > a different mechanism for it and we may be able to patch zsh. } ===================== } } weird.... (FreeBSD 6.2-RELEASE amd64) it sometimes works under bash, } doesn't work under zsh. see below. similar results in a 7.1-STABLE jail, } but it seems more likely to work as desired. Oh, there's probably a race condition then. Try this instead: perl -e '$0 = "Test hiding command"; sleep 10;' & sleep 2; ps $! The extra sleep in the parent shell will give perl a bit longer to get going. Your evidence so far indicates that assigning to $0 in perl is able to change the command, so there must be something perl is doing that "jobs -Z" is not doing. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 22:08 ` Bart Schaefer @ 2009-03-15 22:13 ` Atom Smasher 2009-03-16 2:07 ` Dan Nelson 0 siblings, 1 reply; 11+ messages in thread From: Atom Smasher @ 2009-03-15 22:13 UTC (permalink / raw) To: zsh-users On Sun, 15 Mar 2009, Bart Schaefer wrote: > Oh, there's probably a race condition then. Try this instead: > > perl -e '$0 = "Test hiding command"; sleep 10;' & sleep 2; ps $! > > The extra sleep in the parent shell will give perl a bit longer to get > going. ================= that works. > Your evidence so far indicates that assigning to $0 in perl is able to > change the command, so there must be something perl is doing that "jobs > -Z" is not doing. =================== seems like it. thanks... -- ...atom ________________________ http://atom.smasher.org/ 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808 ------------------------------------------------- "Now about Lankhmar. She's been invaded, her walls breached everywhere and desperate fighting is going on in the streets, by a fierce host which out-numbers Lankhmar's inhabitants by fifty to one -- and equipped with all modern weapons. Yet you can save the city." "How?" demanded Fafhrd. Ningauble shrugged. "You're a hero. You should know." -- Fritz Leiber, "The Swords of Lankhmar" ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-15 22:13 ` Atom Smasher @ 2009-03-16 2:07 ` Dan Nelson 2009-03-16 4:08 ` Bart Schaefer 0 siblings, 1 reply; 11+ messages in thread From: Dan Nelson @ 2009-03-16 2:07 UTC (permalink / raw) To: Atom Smasher; +Cc: zsh-users In the last episode (Mar 16), Atom Smasher said: > On Sun, 15 Mar 2009, Bart Schaefer wrote: > > > Oh, there's probably a race condition then. Try this instead: > > > > perl -e '$0 = "Test hiding command"; sleep 10;' & sleep 2; ps $! > > > > The extra sleep in the parent shell will give perl a bit longer to get > > going. > ================= > > that works. In case it stops working later, all of the *BSDs provide a setproctitle() function to cleanly reset what shows up in ps output. Rewriting argv[0] may cause problems, especially if you started out with a small commandline and environment, or if you have called setenv/putenv/unsetenv. -- Dan Nelson dnelson@allantgroup.com ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-16 2:07 ` Dan Nelson @ 2009-03-16 4:08 ` Bart Schaefer 2009-03-16 4:43 ` Bart Schaefer 0 siblings, 1 reply; 11+ messages in thread From: Bart Schaefer @ 2009-03-16 4:08 UTC (permalink / raw) To: zsh-users On Mar 15, 9:07pm, Dan Nelson wrote: } } In case it stops working later, all of the *BSDs provide a setproctitle() I see there's been some discussion about adding setproctitle() to glibc. Let's try this. diff -ru -x CVS zsh-forge/current/configure.ac zsh-4.0/configure.ac --- zsh-forge/current/configure.ac 2009-03-08 14:01:12.000000000 -0700 +++ zsh-4.0/configure.ac 2009-03-15 20:59:52.000000000 -0700 @@ -1885,6 +1885,11 @@ AC_DEFINE(USE_GETCWD) fi +dnl CHECK FOR setproctitle() FOR jobs -Z / ARGV0 +AH_TEMPLATE([HAVE_SETPROCTITLE], +[Define to 1 if the system supports this call to change process name]) +AC_SEARCH_LIBS(setproctitle, util, AC_DEFINE(HAVE_SETPROCTITLE)) + dnl ------------- dnl CHECK FOR NIS dnl ------------- diff -ru -x CVS zsh-forge/current/Src/jobs.c zsh-4.0/Src/jobs.c --- zsh-forge/current/Src/jobs.c 2009-03-14 23:22:20.000000000 -0700 +++ zsh-4.0/Src/jobs.c 2009-03-15 21:03:13.000000000 -0700 @@ -1572,12 +1572,14 @@ return returnval; } +#ifndef HAVE_SETPROCTITLE /* For jobs -Z (which modifies the shell's name as seen in ps listings). * * hackzero is the start of the safely writable space, and hackspace is * * its length, excluding a final NUL terminator that will always be left. */ static char *hackzero; static int hackspace; +#endif /* Initialise job handling. */ @@ -1600,6 +1602,7 @@ jobtabsize = MAXJOBS_ALLOC; memset(jobtab, 0, init_bytes); +#ifndef HAVE_SETPROCTITLE /* * Initialise the jobs -Z system. The technique is borrowed from * perl: check through the argument and environment space, to see @@ -1622,6 +1625,7 @@ } done: hackspace = p - hackzero; +#endif } @@ -1718,10 +1722,14 @@ } queue_signals(); unmetafy(*argv, &len); +#ifdef HAVE_SETPROCTITLE + setproctitle("%s", *argv); +#else if(len > hackspace) len = hackspace; memcpy(hackzero, *argv, len); memset(hackzero + len, 0, hackspace - len); +#endif unqueue_signals(); return 0; } ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: jobs -Z example? 2009-03-16 4:08 ` Bart Schaefer @ 2009-03-16 4:43 ` Bart Schaefer 0 siblings, 0 replies; 11+ messages in thread From: Bart Schaefer @ 2009-03-16 4:43 UTC (permalink / raw) To: zsh-users On Mar 15, 9:08pm, Bart Schaefer wrote: } } +AC_SEARCH_LIBS(setproctitle, util, AC_DEFINE(HAVE_SETPROCTITLE)) Actually the following is a bit more complete for configure.ac. (Ignore the "4.0" in the directory name, it's the same CVS sandbox I've been using for years and have never bothered to rename.) --- zsh-forge/current/configure.ac 2009-03-08 14:01:12.000000000 -0700 +++ zsh-4.0/configure.ac 2009-03-15 21:26:28.000000000 -0700 @@ -1885,6 +1885,12 @@ AC_DEFINE(USE_GETCWD) fi +dnl CHECK FOR setproctitle() FOR jobs -Z / ARGV0 +AH_TEMPLATE([HAVE_SETPROCTITLE], +[Define to 1 if the system supports `setproctitle' to change process name]) +AC_CHECK_FUNC(setproctitle,AC_DEFINE(HAVE_SETPROCTITLE), +AC_SEARCH_LIBS(setproctitle,util,AC_DEFINE(HAVE_SETPROCTITLE))) + dnl ------------- dnl CHECK FOR NIS dnl ------------- ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2009-03-16 4:46 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-03-15 18:24 jobs -Z example? Atom Smasher 2009-03-15 19:47 ` Bart Schaefer 2009-03-15 20:49 ` Atom Smasher 2009-03-15 21:05 ` Christian Schneider 2009-03-15 21:07 ` Bart Schaefer 2009-03-15 21:41 ` Atom Smasher 2009-03-15 22:08 ` Bart Schaefer 2009-03-15 22:13 ` Atom Smasher 2009-03-16 2:07 ` Dan Nelson 2009-03-16 4:08 ` Bart Schaefer 2009-03-16 4:43 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ 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 NNTP newsgroup(s).