Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

piping stdout of cat to kill's stdin

Name: Anonymous 2008-01-29 23:52

If I have the pid of some process stored in a text file, let's call it program.pid, and I want to end that process via the kill command, how come I can't do this:

bash:$ cat program.pid | kill

But if cat program.pid, and just type the output into the kill command, it works and I stop the process.  Why can't I pipe the output from cat to kill?

Name: Anonymous 2008-01-30 0:01

Wait a second, why does THIS work:

kill `cat program.pid`

And not cat program.pid | kill

Name: Anonymous 2008-01-30 1:44

>>2
In the first example, if the contents of program.pid is ``15'' you're saying kill 15. You're passing the contents as arguments, cat isn't writing to stdout.

kill does not read from stdin.

Name: Anonymous 2008-01-30 1:47

kill < program.pid
kill $(cat program.pid)

Bash is fun.

Name: Anonymous 2008-01-30 14:36

Presumably because you're not running as root, for a start, you dumb shit.

# ps aux | grep penispie > peenooose.pid && kill peenooose.pid

Name: Anonymous 2008-01-30 16:20

>>5
You don't to be root to kill your own processes.

Name: Anonymous 2008-01-30 19:28

>>5
You're a moron. Quit trying to help.

Name: Anonymous 2008-01-31 1:07


Fuck off you should just stay root all the time anyway you have to be fucking stupid to delete something you need or mess it up somehow. Its just a stupid myth that you should ignore really.>>6
>>7

Name: Anonymous 2008-01-31 2:52

>>8
5/10

Not bad.

Name: Anonymous 2008-01-31 12:55

>>9
Considering that it's twenty years old, it's getting kind of stale. Dock some points.

Name: Anonymous 2008-02-01 9:31

>>3

In the first example, if the contents of program.pid is ``15'' you're saying kill 15. You're passing the contents as arguments, cat isn't writing to stdout.

kill does not read from stdin.

You're going to have to elaborate on this for me.  I mean, if cat doesn't write to stdout, then why do commands such as

cat somefile.txt | less
ls > filelist.txt && grep "cp" filelist.txt | rm -vf

work just fine?

Also, call me a faggot if you must, but how did you put the word "kill" in a fixed-width font?

I mean, if the pid of the process I want to kill is "15", and I can kill it by typing "kill 15", why can't I cat program.pid | kill if it's the same as typing "kill 15"?

Name: Anonymous 2008-02-01 13:56

>>11

cat DOES WRITE TO stdout BUT kill DOES NOT READ FROM stdin

NOW GTFO

Name: Anonymous 2008-02-01 13:58

[du]TEST[/du]

Name: Anonymous 2008-02-01 23:29

>>11
You have a bunch of commands called filters that read from stdin.  less is one of them.  kill is not.

You can usually only use | with filter type commands.  Further examples: more, tr, col, grep, sort

Some commands can act as both.  Usually you have to put a - instead of the file name to get it to read from stdin, or in tar's case, specify the f option to make it NOT read from stdin.

>>2
`this` makes the Bash shell replace whatever is inside the ` marks with the stdout of that command.  Very useful.  Example: echo `/bin/date`.

Name: Anonymous 2008-02-02 1:06

>>14

How do you get a fixed-width font?

Name: Anonymous 2008-02-02 1:18

>>15
Like this

Name: Anonymous 2008-02-02 15:45

>>16
Like this?

Name: Anonymous 2008-02-02 17:14

>>17
[b]YOU GOT IT[/b]

Name: Anonymous 2008-02-02 17:33

>>18

YOU GOT IT

you fail at bbcode

Name: Anonymous 2008-02-02 19:58

>>6
Hurf durf durf really? I assumed you could just cock some niggers and be done with it. I was assuming he was killing something important, else how would he predict the job number?

Name: Anonymous 2008-02-02 22:55

>>20
First of all, yes, I'm killing a process I own, and second, I wanted to know this because I'm writing an interactive bash script that allows you to start or stop said process with an idiot-proof exchange. 

Name: Anonymous 2008-02-03 0:14

>>20
How do I shot pidof?

Name: Anonymous 2008-02-06 2:06

>>19
PLEASE GUYS. DON'T BE MEAN TO ME. IM NEW AT THIS.

Name: Anonymous 2008-02-06 13:38

>>14

This is excellent information.  Where can I get a canonical list of all filters and non?

Name: Anonymous 2008-02-06 14:07

>>24
man <program>

Name: Anonymous 2008-02-06 14:25

>>25

Uh, wouldn't that require me to read the manual for ALL programs?  I asked for a list of programs that don't read from STDIN.

Also, the man for kill says nothing about whether or not it reads from STDIN.

http://linux.die.net/man/2/kill

Name: Anonymous 2008-02-06 14:41

>>26
Yes, you'd need to read the man page for every program you're interested in. Making a list of all programs ever written would be slightly unfeasible and incredibly useless.

kill's man page doesn't mention it reads from stdin, so it's safe to assume it doesn't.
It also doesn't mention it can't exit with a return value of 9000, but since it doesn't explicitly mention it can, it's safe to assume it can't.

What the fuck is wrong with you?

Name: Anonymous 2008-02-06 14:56

>>26
Also, kill(1) != kill(2)

Name: Anonymous 2008-02-06 23:41

How to tell if a program reads from stdin

1 - Invoke program
2 - If your terminal sits there, waiting for you to type something, type something and then hit Ctrl-D
3 - If the command continued, it wanted some stdin
4 - If it prints usage or does something without waiting, it didn't want any

Name: Anonymous 2008-02-08 10:42

>>29
I lol'd

Name: Anonymous 2008-02-08 23:15

>>30

>>29 here
It made sense to me when I wrote it.  I blame the tequila i was drinking.

Name: Anonymous 2008-02-09 9:19

Unless programs specifically say that they do shit with stdin, they don't.

Name: Anonymous 2008-02-17 22:59

>>32

Uhh, ok then, please explain to me how a program like less can read piped input, but by your definition does not ready from stdin?

In other words, cat ~/longfile.txt | less works fine, but there is no mention of stdin in that program's man file?

Name: Anonymous 2008-02-18 2:54

>>33
Because everyone that has used Unix for more than two weeks knows how less works. Well it used to be that way. The manual page didn't take UBANTOfags into account.

Name: Anonymous 2008-02-18 21:58

>>33
useless use of cat is why.

Name: Anonymous 2008-02-19 16:08

proper use of cat follows

cat porn.avi.00* > porn.avi

Name: Anonymous 2008-02-19 16:11

>>36
Why not use mv to rename your avi file?

Name: Anonymous 2008-02-19 16:18

* = wildcard, hence there is a porn.avi.001 porn.avi.002 etc, and I like cat.

Name: Anonymous 2008-02-19 18:58

>>36,38
cp will be faster.

Name: Anonymous 2008-02-19 19:02

>>39
cat = CONcatENATE

now gtfo.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List