LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-08-2018, 10:47 AM   #1
miaumezu
LQ Newbie
 
Registered: Dec 2018
Posts: 5

Rep: Reputation: Disabled
A progam in C works sometimes and sometimes not.


Hi everyone!
I have a problem with a program that I am creating, I have uploaded it to github, https://github.com/miaumezu/pow, it 's supposed to kill all processes till it has permissions, but sometimes unlogs the user, sometimes closes windows, and sometimes it does nothing.
Thanks .
 
Old 12-08-2018, 11:17 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Generally speaking, the first step to debugging a program that gives different results "sometimes" is to determine what those "sometimes" are.

But your program just kills processes in numerical pid order, right? And it doesn't care what those processes are? I'm not sure what you expect it to do differently.

Last edited by dugan; 12-08-2018 at 11:21 AM.
 
1 members found this post helpful.
Old 12-08-2018, 11:20 AM   #3
miaumezu
LQ Newbie
 
Registered: Dec 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Exclamation

Quote:
Originally Posted by dugan View Post
Step one: determine what the "sometimes" are.
The word says it, the program is supposed to kill all processes that the user can kill, but it kills only some of them, if you try another time, it maybe close the user session, etc.
 
Old 12-08-2018, 11:23 AM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Well, gee, if the user session just happens to be early in the list of processes that the user can kill, and your program kills it, then how do you expect it to continue?
 
1 members found this post helpful.
Old 12-08-2018, 11:29 AM   #5
miaumezu
LQ Newbie
 
Registered: Dec 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
Generally speaking, the first step to debugging a program that gives different results "sometimes" is to determine what those "sometimes" are.

But your program just kills processes in numerical pid order, right? And it doesn't care what those processes are? I'm not sure what you expect it to do differently.
Yes, it is supposed to kill the processes ignoring what they are, I expect only a kind of bomb, it kills all the processes without looking what they are.
 
Old 12-08-2018, 11:33 AM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Hint: the user session and the terminal it ran it both count as processes the user account have kill-access to.
 
1 members found this post helpful.
Old 12-08-2018, 11:35 AM   #7
miaumezu
LQ Newbie
 
Registered: Dec 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
Hint: the user session and the terminal it ran it both count as processes the user account have kill-access to.
So the program kills also the terminal where is executed, no ? It 's supposed to protect himself but no the pid of the terminal where it is.
 
Old 12-08-2018, 11:44 AM   #8
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 483

Rep: Reputation: 153Reputation: 153
Quote:
The word says it, the program is supposed to kill all processes that the user can kill, but it kills only some of them, if you try another time, it maybe close the user session, etc.
There is a user on LQ that has a tagline similar to "A program will never do what was intended, only what was implemented." This is the case here. This is what you implemented.

By blindly killing all user processes this is what will happen. The user session is a user process so killing it will close the user session. I notice that you are avoiding the process id of the program itself but if you kill the bash shell from which it was invoked it will also kill your program resulting in incomplete execution. You also don't check if there is a process 99999 or 99998 ... and so are trying to kill thousands of non-existent processes.

Your "program" is of no use to anyone in this state and should be removed from github. You should never upload anything that doesn't work or has never been tested or is fundamentally flawed in concept.
 
1 members found this post helpful.
Old 12-08-2018, 11:52 AM   #9
miaumezu
LQ Newbie
 
Registered: Dec 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tofino_surfer View Post
Your "program" is of no use to anyone in this state and should be removed from github. You should never upload anything that doesn't work or has never been tested or is fundamentally flawed in concept.
Because of that I am asking this, for correcting it.

Last edited by miaumezu; 12-08-2018 at 11:54 AM.
 
Old 12-11-2018, 07:57 AM   #10
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Maybe you need to better define what should be killed and what shouldn't? No-one knows exactly what your program is supposed to be doing differently, and when asked, all you've said was "it's supposed kill processes". Which it already does. Edit: And "I was expecting a bomb". Which it already is.

Last edited by dugan; 12-11-2018 at 11:55 AM.
 
Old 12-11-2018, 09:02 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
yes, it sounds like you're going to have to put some checks in place to prevent it from killing the desktop/ window manger especially into your code. I even use that sometimes to kill my window manager whenever I lock it up, and can still use a keyboard that is.

as far as looking at your program, to maybe through you a bone, well, "404 Page not found", you must have killed that too.

Last edited by BW-userx; 12-11-2018 at 09:04 AM.
 
  


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
Synaptics TouchPad sometimes works,sometimes not Salgeras Linux - Laptop and Netbook 2 06-08-2007 03:20 AM
wireless internet sometimes works and sometimes doesn't alexdebian Linux - Wireless Networking 2 02-18-2007 01:45 PM
My microphone sometimes works and sometimes doesn't mf5160 Linux - Hardware 1 11-03-2006 09:03 PM
automatic shutdown of Mandrake 9.2 (sometimes works sometimes not) lu543285 Linux - Hardware 1 02-06-2004 12:18 PM
Quake3: Sometimes works, sometimes doesn't migo Linux - Software 2 02-03-2003 02:16 PM

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

All times are GMT -5. The time now is 06:32 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