Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged PID from sorted by
Terminal - Commands tagged PID - 8 results
ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'
2014-11-26 21:29:33
User: krizzo
Functions: awk ps
0

This prints out a list of all zombie processes PIDs so you can do things like kill the zombies

PID=$(ps -ef | grep processName | grep -v grep | awk '{print $2'}); kill -9 $PID
ps -eo pid,lstart,cmd
2013-06-17 12:52:53
User: kruspemsv
Functions: ps
Tags: PID
12

That is useful to discover the start time of process older than 1 day.

You can also run:

ls -ld /proc/PID

That's returning the creation date of the proc files from the process. Some users reported that this way might show you a wrong date since any other process like cron, for example, could change this date.

readlink -f /proc/$pid/exe
xprop | awk '/PID/ {print $3}'
sh time.sh 1 20 & var1="$!" & sh time.sh 2 10 & var2="$!" & sh time.sh 3 40 & var3="$!" & sh time.sh 4 30 & var4="$!" ; wait $var1 && wait $var2 && wait $var3 && wait $var4
2012-03-31 10:03:58
User: julnegre
Functions: sh wait
0

This command explains how to manage some asynchronous PID in a global process.

The command uses 4 processes in a global process. The asynchronous scripts are simulated by a time.sh script

more infos :

http://code-esperluette.blogspot.fr/2012/03/bash-gestion-de-processus-asynchrones.html

http://www.youtube.com/watch?v=TxsPyAtD70I

command & echo $!
2011-06-08 18:16:38
User: Mahrud
Functions: command echo
-2

Actually $! is an internal variable containing PID of the last job in background.

More info: http://tldp.org/LDP/abs/html/internalvariables.html#PIDVARREF

Using $! for job control:

possibly_hanging_job & { sleep ${TIMEOUT}; eval 'kill -9 $!' &> /dev/null; }
lsof -p 15857