LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2007, 12:51 PM   #16
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31

Back to the original, unhijacked (grin) question:

There's a way to do this that's possibly simpler than your C code.

Open the /proc directory, as you're doing. Concentrate on the process names by concentrating on numbers, as you're doing.

For process 2345, for example, look at 2345/exe, which is a symbolic link. It links to whatever is being executed, like /bin/bash. That gives you the name of the program you're running. It's arguably easier to read a symbolic link than to parse text.

It's also fun to try the proof of concept on the command line, since bash will use its own process number when you put $$ on the command line:

Code:
ls -l /proc/$$/exe
Um, since you're already concentrating on numbered processes, you can leave out the explicit check for "..".

Hope this helps.

Last edited by wjevans_7d1@yahoo.co; 04-19-2007 at 12:56 PM.
 
Old 04-20-2007, 01:20 PM   #17
culin
Member
 
Registered: Sep 2006
Distribution: Fedora Core 10
Posts: 254

Original Poster
Rep: Reputation: 32
Hi wjevans_7d1@yahoo.co,
i am doing what u told in the code posted before... but there is a problem with this code.. i think.. may be its the drawback of the code...
say i will run and executable named ./testing from a program inside which i will be doing execl() or execvp(./testing , "the name by which executable has to be spawned")
say execvp(./testing, test);
now if do a ps -aux then it will be showing the process named "test" with so and so pid... now if i want to have the pid of the process running "test" by my code what i had posted.. it is returning -1... also killall -9 test will tell that no such process.. even though ps -aux shows that it is running with some pid.. but when i do "/sbin/pidof test" this gives the pid with what it is running..
so why killall -9 test wont kill that process ????????
 
Old 04-21-2007, 05:41 PM   #18
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
culin, I'm having difficult understanding what you're saying. Could you translate that into a small C program? (Maybe you already have that as part of a larger program.) Then post here the entire small program, what you typed at the command line to run it, and the exact output it gave.

I think that will take you less time than it will for me to figure out what you said. Sorry. (grin)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
Need to install process at end of boot process ch485de Linux - Newbie 5 12-07-2006 05:47 PM
child process usses same amount of ram as parent process socialjazz Programming 7 10-19-2006 05:48 PM
Process Table-Process Control Block sarahmencer Linux - General 1 01-09-2006 09:14 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration