LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 06-16-2004, 04:17 PM   #1
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843
Blog Entries: 1

Rep: Reputation: 30
how to kill a process in C++?


Well...
What kind of call do I do in c++ to kill a command/process?

Have a nice program I wanna make
 
Old 06-16-2004, 04:21 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
'man kill' , send the SIGKILL signal.
 
Old 06-16-2004, 04:36 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
There are two man pages on kill. The one you want is prolly:
Quote:
NAME
kill(), raise() - send a signal to a process or a group of processes

SYNOPSIS
#include <signal.h>

int kill(pid_t pid, int sig);

int raise(int sig);

DESCRIPTION
The kill() system call sends a signal to a process or a group of
processes, as specified by pid. The signal to be sent is specified by
sig and is either one from the list given in signal(2), or 0.
You would include <signal.h> and send the SIGKILL message.
 
Old 06-16-2004, 04:51 PM   #4
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843

Original Poster
Blog Entries: 1

Rep: Reputation: 30
Talking good!

what is raise() for...

and...

how do a program collect all the process it (the program) can kill/renice
e.g., if your not root and are searching for the processes which you have permission over?


Forgot one thing too

how do you renice?
renice() ?

time elapse for answer was below 30 minutes

Jeremie, your site is SO cool!
 
Old 06-16-2004, 05:30 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
raise() sends a signal to the process itself.

You can kill only those processes you own, unless you have privilege.

Code:
ps -ef | grep "mimithebrain"
will show you processes you own - with the exception of sshd sessions.
 
Old 06-16-2004, 05:34 PM   #6
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843

Original Poster
Blog Entries: 1

Rep: Reputation: 30
Result:
mimithe 2516 2390 0 15:04 ? 00:00:00 kdeinit: kio_file file /tmp/ksocket-mimithebrain/klauncherRKyNya.slave-socket /tmp/ksocket-mimithebrain/konquerorTaiIza.slave-socket
mimithe 2552 2390 0 15:30 ? 00:00:00 kdeinit: kio_http http /tmp/ksocket-mimithebrain/klauncherRKyNya.slave-socket /tmp/ksocket-mimithebrain/konquerorUj8Lsb.slave-socket
mimithe 2553 2390 0 15:30 ? 00:00:00 kdeinit: kio_http http /tmp/ksocket-mimithebrain/klauncherRKyNya.slave-socket /tmp/ksocket-mimithebrain/konquerorFphKab.slave-socket
mimithe 2554 2390 0 15:30 ? 00:00:00 kdeinit: kio_http http /tmp/ksocket-mimithebrain/klauncherRKyNya.slave-socket /tmp/ksocket-mimithebrain/konqueror8IUGla.slave-socket
mimithe 2556 2390 0 15:30 ? 00:00:00 kdeinit: kio_http http /tmp/ksocket-mimithebrain/klauncherRKyNya.slave-socket /tmp/ksocket-mimithebrain/konquerorwDWKna.slave-socket
mimithe 2559 2390 0 15:30 ? 00:00:00 kdeinit: kio_http http /tmp/ksocket-mimithebrain/klauncherRKyNya.slave-socket /tmp/ksocket-mimithebrain/konquerorT1UnFb.slave-socket
mimithe 2560 2390 0 15:30 ? 00:00:00 kdeinit: kio_http http /tmp/ksocket-mimithebrain/klauncherRKyNya.slave-socket /tmp/ksocket-mimithebrain/konquerorguvwfa.slave-socket

nice, but I have way more processes than that
cool commands you told me, is there something of the same kind which permits you to get a same/close result?

a command in C++
 
Old 06-17-2004, 03:45 PM   #7
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843

Original Poster
Blog Entries: 1

Rep: Reputation: 30
One more thing

how do you retrieve the running application PID (the one I'm programming?)
 
Old 06-17-2004, 04:54 PM   #8
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
getpid() - get current proc pid
getppid() - get parent's pid
 
Old 06-17-2004, 05:17 PM   #9
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843

Original Poster
Blog Entries: 1

Rep: Reputation: 30
right,
now how to get the memory usage of a certain PID?
 
Old 06-17-2004, 05:20 PM   #10
mimithebrain
Member
 
Registered: Nov 2003
Location: ~
Distribution: Ubuntu 10.04
Posts: 843

Original Poster
Blog Entries: 1

Rep: Reputation: 30
oops!!?!
I asked this question somewere else!!??!

sry for the inconvinience
the answer to this should be at
http://www.linuxquestions.org/questi...hreadid=191394
soon or later...
 
  


Reply



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
Process won't kill mrsolo Linux - Software 5 08-03-2007 12:45 PM
I want to kill process Jeon, Chang-Min Linux - General 6 08-09-2005 12:14 AM
cannot kill process (kill -9 does not work) mazer13a Linux - General 1 05-27-2005 02:32 PM
Cannot kill process Zeno McDohl Linux - General 13 04-14-2005 02:31 PM
can't kill the process ust Linux - Software 1 09-15-2004 06:05 AM

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

All times are GMT -5. The time now is 10:19 AM.

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