ps interview questions
Top ps frequently asked interview questions
I’d like to view information for processes running in OS X. Running ps
in the terminal just lists the open Terminal windows. How can I see all processes that are running?
Say I’m running a web browser, terminal and text editor. I’d like to see information for the text editor and web browser.
Source: (StackOverflow)
Can I change effective process name of a Python script? I want to show a different name instead of the real name of the process when I get the system process list. In C I can set
strcpy(argv[0],"othername");
But in Python
argv[0] = "othername"
doesn't seem to work. When i get process list (with ps ax
in my linux box) the real name doesn't change. I prefer a portable solution (or else one solution for posix and another for windows environments), if it exists.
Thanks in advance
Source: (StackOverflow)
I'm having an issue with attempting to save some plots with transparent ellipsoids on them if I attempt to save them with .ps/.eps extensions.
Here's the plot saved as a .png:
If I choose to save it as a .ps/.eps here is what it looks like:
How I got around this, was to use ImageMagick to convert the original png to a ps. The only problem is that the image in png format is about 90k, and it becomes just under 4M after conversion. This is not good since I have a lot of these images, and it will take too much time to compile my latex document. Does anyone have a solution to this?
Source: (StackOverflow)
Well it goes like this, I had to run a program from my home by ssh
ing into the server in my institution. I did not want my program to be terminated when the session closes(I didn't know about screen
).
What i did was press Ctrl+Z
and then type bg
so that it executes in the background.
The session got terminated. Now when I login from my institution machine and type ps -u username
, it shows that the program is still running but I'm unable to bring it to foreground.
I tried fg
and jobs
but these commands don't give me any output.
Please someone help me..
Source: (StackOverflow)
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main() {
int res = system("ps ax -o pid -o command | grep sudoku | grep gnome > /dev/null");
printf("res = %d \n", res);
return 0;
}
I want to see if sudoku
is running or not by just examining the return code of system()
(or any other call for that matter). I do not want any output to be printed anywhere.
I do not quite understand the return code of system()
even after looking at the man page
Whether sudoku
is running or not, I get res = 0
.
Source: (StackOverflow)
This is an example of a bash script which checks for some running process (daemon or service) and does specific actions (reload, sends mail) if there is no such process running.
check_process(){
# check the args
if [ "$1" = "" ];
then
return 0
fi
#PROCESS_NUM => get the process number regarding the given thread name
PROCESS_NUM='ps -ef | grep "$1" | grep -v "grep" | wc -l'
# for degbuging...
$PROCESS_NUM
if [ $PROCESS_NUM -eq 1 ];
then
return 1
else
return 0
fi
}
# check wheter the instance of thread exsits
while [ 1 ] ; do
echo 'begin checking...'
check_process "python test_demo.py" # the thread name
CHECK_RET = $?
if [ $CHECK_RET -eq 0 ]; # none exist
then
# do something...
fi
sleep 60
done
However, It doesn't work. I got "ERROR: Garbage option." for ps command. What's wrong with this scripts, thanks!
Source: (StackOverflow)
Hello I am using MPJ library in java program for Pagerank algorithm.
I compile it by
javac -cp .:$MPJ_HOME/lib/mpj.jar MpiPageRank.java
and run by
mpjrun.sh -np 2 MpiPageRank
where -np
is number of process
Now i have to find its pid
ps -ef|grep java
like
mpjrun.sh -np 2 MpiPageRank & sleep 2
ps -ef | grep java
I get
pnewaska 27866 27837 99 21:28 pts/45 00:00:09 java -cp /u/pnewaska/mpj-v0_38/lib/smpdev.jar:/u/pnewaska/mpj-v0_38/lib/xdev.jar:/u/pnewaska/mpj-v0_38/lib/mpjbuf.jar:/u/pnewaska/mpj-v0_38/lib/loader2.jar:/u/pnewaska/mpj-v0_38/lib/starter.jar:/u/pnewaska/mpj-v0_38/lib/mpiExp.jar runtime.starter.MulticoreStarter /nfs/nfs1/home/pnewaska/DistributedSystems/Project3 10 smpdev useLocalLoader EMPTY MpiPageRank -i input.500k0 -n 10 -o
Now I want to extract MpiPageRank
from only 1 linux comman to get its pid ie 27866
.
how do i do that ?
Source: (StackOverflow)
I tried to remove a file in Linux using rm -rf file_name
, but got the error:
rm: file_name not removed. Text file busy
.
How can I find out which process is using this file?
Source: (StackOverflow)
I'm trying to identify when a particular process is running, based on its arguments, on Mac OS X. There may be several processes running with the same name, but only one will have the arguments I'm looking for. The processes are not owned by the same user who will be running my code. They will not have modified their argv in any way.
The 'ps' command shows exactly the information that I need. But I would greatly prefer not to have to spawn 'ps' and parse its output.
I originally tried the solution from this question, using sysctl, but it turns out that only works for processes you own; see my other question for more info.
So how does ps obtain argv information for processes owned by other users?
Source: (StackOverflow)
Is there a way to set argv[0]
in a Haskell program (say, one compiled with ghc)?
I found the getProgName
and withProgName
functions in System.Environment, but it doesn't seem to change what ps
reports (Ubuntu).
import System.Environment
main =
do name <- getProgName
putStrLn $ "Hello, my name is " ++ name
withProgName "other" $ do
newname <- getProgName
putStrLn $ "Name now set to " ++ newname
putStrLn "What is your name: "
-- allow time to run ps
ans <- getLine
putStrLn $ "Pleased to meet you, " ++ ans
Source: (StackOverflow)
I'm working on an application that monitors the processes' resources and gives a periodic report in Linux, but I faced a problem in extracting the open files count per process.
This takes quite a while if I take all of the files and group them according to their PID and count them.
How can I take the open files count for each process in Linux?
Source: (StackOverflow)
I have a process that is running in the background (sh script) and I wonder if it is possible to view the output of this process without having to interrupt it.
The process ran by some application otherwise I would have attached it to a screen for later viewing. It might take an hour to finish and i want to make sure it's running normally with no errors.
Source: (StackOverflow)
I need to extract PID, UID and command fields from 'ps' and I have tried it like this:
ps -L u n | cut -f 1,2,13
For some reason, this behaves as there is no cut command whatsoever. It just returns normal ps output. Then, I tried
ps -L u n | tr -s " " | cut -d " " -f 1,2,13
and this returns total nonsense. Then, I tried playing with it and with this:
ps -L u n | tr -s " " | cut -d " " -f 2,3,14
and this somehow returns what I need (almost, and I don't understand why that almost works), except that it cuts out the command field in the middle of it. How can I get what I need?
Source: (StackOverflow)
I am using this command to get the process ID of another command:
ps aux | grep 7000.conf | awk '{print $2}'
This will return two PIDs:
7731
22125
I only want the first one. The second is the PID for grep
in the above command. Thanks in advance to any one who knows how to alter the above command to return just the first pid.
p.s. open to a new command that does the same thing
Source: (StackOverflow)