Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Notorious b.s.d.
Jan 25, 2003

by Reene

Bhodi posted:

Just spent 10 minutes on google; simple answer: You can't. At least not trivially. The poo poo's splattered all over the system and stored in /proc and various other places, from what I can gather.

it's extremely easy in most languages

Perl code:
#!/usr/bin/env perl

$0='lol';
sleep
code:
$ ps -a | grep lol
15906 pts/17   00:00:00 lol
$ cat /proc/15906/cmdline 
lol

Adbot
ADBOT LOVES YOU

bobbilljim
May 29, 2013

this christmas feels like the very first christmas to me
:shittydog::shittydog::shittydog:
e: ^ well whata ya know
i dont know if many ruby programs manage it lol

Bhodi
Dec 9, 2007

Oh, it's just a cat.
Pillbug
I've never had the balls to try and edit a /proc/pid/cmdline so I don't know.

This really scary blog entry says it's possible with compiled c: http://stupefydeveloper.blogspot.com/2008/10/linux-change-process-name.html

I sure as hell wouldn't want to play with that in production though

I'm pretty sure your simple example has flaws, because I'm certain I read that you can change it after execution but it doesn't store that in /proc, only locally somehow. I'll play around with it tomorrow.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

try setting $1?

changing argv[0] requires some work on certain systems (setproctitle or equiv) but copying into the right other element of argv should be simpler

Bhodi
Dec 9, 2007

Oh, it's just a cat.
Pillbug
Yeah dunno if it (setting argv[0]) works in ruby, it doesn't in python apparently http://stackoverflow.com/questions/564695/is-there-a-way-to-change-effective-process-name-in-python but some guy wrote a thing to do it https://code.google.com/p/py-setproctitle/

E: ah ha, snack overflow: http://stackoverflow.com/questions/450620/change-the-ruby-process-name-in-top

Bhodi fucked around with this message at 05:11 on Feb 24, 2015

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Bhodi posted:

I've never had the balls to try and edit a /proc/pid/cmdline so I don't know.

This really scary blog entry says it's possible with compiled c: http://stupefydeveloper.blogspot.com/2008/10/linux-change-process-name.html

I sure as hell wouldn't want to play with that in production though

I'm pretty sure your simple example has flaws, because I'm certain I read that you can change it after execution but it doesn't store that in /proc, only locally somehow. I'll play around with it tomorrow.

that scary blog entry is about changing another process' argv, not your own

nothing is stored in /proc, it's all computed from process data. if you just want to mask out a password then overwriting that element of argv should be portable. whether that requires FFI in ruby depends on how magic its reflections of argv are

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
just write your own top idgi

why do you want to change the name anyhow

Bhodi
Dec 9, 2007

Oh, it's just a cat.
Pillbug
And they call me a senior sysguy.... christ. I hope no one from work ever sees this thread

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal

Bloody posted:

just because you are struggling to chop down a tree with a hammer does not mean the hammer is faulty

it means you're 16 and just because you can doesn't mean you should :downs:

alternate answer: it just means the hammer's ill-fitted for the job and the tool manufacturer refuses to produce anything else

Notorious b.s.d.
Jan 25, 2003

by Reene

MALE SHOEGAZE posted:

just write your own top idgi

why do you want to change the name anyhow

to delete passwords from the cmd args

Notorious b.s.d.
Jan 25, 2003

by Reene

ruby is just like perl, you just set $0='whatever'
(yes the $ is required)

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

bucketmouse posted:

and then you implement a dynamically-typed tableview in it and you stop having this delusion

adding objects to c has been done horribly by many and beautifully by a few.

objective-c all the way.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
i think objective c was a really bad place for me to learn about memory and stuff

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal
obj-c owns owns owns for stuff like uis or anything where you want to wildly spew messages at arbitrary collections of objects and not give a gently caress

sucks to see people try to write math libs and such in pure objc though and just not understand why their algorithm's furious message passing runs at like 1/10th of the speed it did in matlab

qntm
Jun 17, 2009

Notorious b.s.d. posted:

it's extremely easy in most languages

Perl code:
#!/usr/bin/env perl

$0='lol';
sleep
code:
$ ps -a | grep lol
15906 pts/17   00:00:00 lol
$ cat /proc/15906/cmdline 
lol

hey I just got a great idea for a new inter-process communication method

Brain Candy
May 18, 2006

qntm posted:

hey I just got a great idea for a new inter-process communication method

:gonk:

Condiv
May 7, 2008

Sorry to undo the effort of paying a domestic abuser $10 to own this poster, but I am going to lose my dang mind if I keep seeing multiple posters who appear to be Baloogan.

With love,
a mod


i'm thinking of rewriting a process management system that's written entirely in bash in java or scala, cause i need to add a bunch of new features to this thing and i feel like bash is just getting in the way

i'm doing something similar for a website we have that is sloppily coded in php

should i just be bashing the new features and designs everyone wants into these lovely programs in lovely languages or is rewriting acceptible in this case?

MononcQc
May 29, 2007

Try Erlang :smuggo:

hobbesmaster
Jan 28, 2008


just use files

Shaggar
Apr 26, 2006

Condiv posted:

i'm thinking of rewriting a process management system that's written entirely in bash in java or scala, cause i need to add a bunch of new features to this thing and i feel like bash is just getting in the way

i'm doing something similar for a website we have that is sloppily coded in php

should i just be bashing the new features and designs everyone wants into these lovely programs in lovely languages or is rewriting acceptible in this case?

use java or c#

Shaggar
Apr 26, 2006
Adding on to the existing systems will only make them harder to fix in the future. Trying to go to a fad lang will only cause headaches and get in the way of implementation. Using java or c# will allow you to quickly and efficiently address the problem with the least amount of work possible.

Notorious b.s.d.
Jan 25, 2003

by Reene
i'm not usually a fan of ground-up rewrites, but rewriting a bash codebase into pretty much anything else is a good idea

  • bash is not debuggable.
    (it has third party debuggers but they don't work well)

  • bash code is not usually testable
    (how can you refactor if you can't test? how can you test if you have to massively refactor to get the first test working?)

  • it's hard to find staff to work on a bash codebase
    (everyone "knows" bash, but people with experience with non-trivial shell scripting are rare. and usually old.)

Share Bear
Apr 27, 2004

you can use perl

more like a slight step sideways and upward, not unlike a handicap ramp, but it is debuggable and can be written clearly and has a ton of good libraries in cpan

Share Bear
Apr 27, 2004

yes you can recommend perl to replace bash things thats what it was for

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Share Bear posted:

yes you can recommend perl to replace bash things thats what it was for

yeah, this is basically the sweet spot for Perl

I had to (read: mustered the courage and political capital to) rebuild a 10KLOC bash test suite runner in another language, and the approach that worked best was to factor into the smallest commands possible, replace those commands with standalone programs in the new language, and then merge those micro-programs as appropriate once things were converted. writing unit tests for the small components was tractable, but the initial factoring was basically leap-of-faith and lots of set -x.

Bhodi
Dec 9, 2007

Oh, it's just a cat.
Pillbug
If you're rewriting something today, I'd think python might be a better choice for that over perl. Perl is good for one-liners and scripts that do one thing, commands you want to pipe in/out of STDIN, python is better for larger, more fully featured programs with a bunch of components. Plus, I don't know anyone who's under 25 who knows perl at all. I don't think they really teach it anymore; and most newer "OS-y" things are being written in python over perl (or ruby....)

I'd break into a cold sweat if I was asked to manage a process management system in bash.


BTW Notorious bsd, thanks, it works
code:
    # Strip out the password so it doesn't show up in ps, still shows up in bash_history :(
    argvs = ARGV.dup
    ["--password", "-p"].each { |p| argvs[argvs.index(p) + 1] = "x"*8 if argvs.index(p) }
    $0 = "#{$0} " + argvs.join(" ")

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

python's process control stuff is a pile of rear end, though maybe that's mostly on windows

Soricidus
Oct 21, 2010
freedom-hating statist shill

Subjunctive posted:

python's process control stuff is a pile of rear end, though maybe that's mostly on windows

if you mean the subprocess module then it's pretty bad on linux too

then again I've never used a process control library that wasn't a pile of rear end so maybe it's an inherently horrible thing to do

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Soricidus posted:

if you mean the subprocess module then it's pretty bad on linux too

then again I've never used a process control library that wasn't a pile of rear end so maybe it's an inherently horrible thing to do

it's awkward as heck but still better than bash scripting

Notorious b.s.d.
Jan 25, 2003

by Reene
arguing about whether to replace shell scripts with ruby, perl, or python is dumbfuck bikeshedding.

i really, honestly don't care which one is chosen. they're all good in this problem space. i'm happy to work with scripts written in any one of them.

just don't use bash.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Notorious b.s.d. posted:

just don't use bash.

you're lucky if people are only using bash

imagine if they were using ksh. ksh88, that is. or csh, and I don't mean tcsh.

sometimes, even bash is a step in the right direction.

bobbilljim
May 29, 2013

this christmas feels like the very first christmas to me
:shittydog::shittydog::shittydog:

qntm posted:

hey I just got a great idea for a new inter-process communication method

Notorious b.s.d.
Jan 25, 2003

by Reene

Soricidus posted:

you're lucky if people are only using bash

imagine if they were using ksh. ksh88, that is. or csh, and I don't mean tcsh.

sometimes, even bash is a step in the right direction.

ksh and bash are pretty much equivalent. even ksh88. i give no fucks

i've never seen a large codebase in csh. i think it's so user-hostile in non-interactive use, it defies the attempt

b0lt
Apr 29, 2005

Notorious b.s.d. posted:

arguing about whether to replace shell scripts with ruby, perl, or python is dumbfuck bikeshedding.

i really, honestly don't care which one is chosen. they're all good in this problem space. i'm happy to work with scripts written in any one of them.

just don't use bash.

use scala

triple sulk
Sep 17, 2014



b0lt posted:

use scala

no don't

Soricidus
Oct 21, 2010
freedom-hating statist shill

Notorious b.s.d. posted:

ksh and bash are pretty much equivalent. even ksh88. i give no fucks

the thing with a large codebase in ksh88 is that so much of it is almost but not quite the same as bash ... so even if you find a shell scripting wizard to maintain it, odds are they'll gently caress it up in the attempt.

as for csh, I'll admit I haven't seen large codebases in it, but I've certainly seen a system that used it exclusively for the glue, and it was every bit as bad as you think.

suffix
Jul 27, 2013

Wheeee!

qntm posted:

hey I just got a great idea for a new inter-process communication method

how about a log system

http://cr.yp.to/daemontools/readproctitle.html

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Notorious b.s.d. posted:

arguing about whether to replace shell scripts with ruby, perl, or python is dumbfuck bikeshedding.

i really, honestly don't care which one is chosen.

youre in luck then, because it's not your decision to make in this instance

suffix
Jul 27, 2013

Wheeee!

Condiv posted:

i'm thinking of rewriting a process management system that's written entirely in bash in java or scala, cause i need to add a bunch of new features to this thing and i feel like bash is just getting in the way

i'm doing something similar for a website we have that is sloppily coded in php

should i just be bashing the new features and designs everyone wants into these lovely programs in lovely languages or is rewriting acceptible in this case?

ideally start by finding a premade tool or library that will do 90% of the stuff you want and make a wrapper on that

i guess that sounds obvious, but i've been burnt before by kind of assuming that if someone made a huge custom shell script for this 5 years ago, there couldn't possibly be a generic simple solution somewhere on github now.

Adbot
ADBOT LOVES YOU

Corla Plankun
May 8, 2007

improve the lives of everyone
wrote and then resolved my first redmine ticket ever today

i even had to do a git

  • Locked thread