implement ps command in linux using C

This tutorial is to help you to implement ps command in linux using C.
ps command provides the list of all the currently running processes in the system.





ps command is also one of the most useful bash command
and is implemented in various ways.

It can help us to see the list of all
  • info about the threads
  • security information
  • each process running as the root.
  • processes with their particular PIDs
For eg,  open up the terminal and write the command
root@kali:~#  ps   -e
It will print all the currently running processes.
implement ps command in linux using C


So let's implement ps command using C
Below is the simple C code to pace up our learning process


#include<stdio.h>
#include<stdlib.h>
void main()
{
printf("It'll print all the currently running processes");
system("ps -e");
}


system is the C library function to excute the bash command

I've saved it by named pscommand.c on Desktop
the output is shown to you by the next screenshot.

implement ps command in linux using C
how to compile c program in linux



Let use our ps command more briefly in C.
Here is another C code to implement ps command.

#include<stdio.h>
#include<unistd.h>
void main()
{
printf("It'll print all the currently running processes in the long format\n");
execl("/bash/ps","ps","-el",NULL);
}


  • execl executes list of command line arguments.  Last parameter is end of argument and always be NULL
  • -l in ps is used to print the data in long format
  • I've saved this file with name pscommand2.c on my desktop


implement ps command in linux using C

So guys, it is all about to implement ps command in linux using C.
Remember, there is no end to this.
So just go deeper and deeper and learn more.

3 comments:

  1. I remember my experience with hackers i contacted online, i almost lost hope in finding out if my husband was loyal to me and has been loyal in our 20 years marriage,I lost a lot of funds in paying these so called hackers so i made up my mind that if i get scammed again i'll just forget about finding out what God doesn't want me to know, Then i saw reviews about ( HACKINTECHNOLOGY@GMAIL.COM ) and decided contact him and if and if i hear any stupid excuse won't contact anybody and just accept that God doesn't want me to then he proved to me that he isn't a cheat by working a sample job for me but to my greatest surprise he did the job and sent results to me fast, i was so happy but sad part was i divorced my husband, and i will drop an advise for people who wants any kind of hacking services stopped being scammed by people who impersonate being hackers, (ETHICALHACKERS009@GMAIL.COM) for a fast and clean job.Here is his cell number +1 (669) 225 2253 , Thank me later.

    ReplyDelete
  2. Hello guys, I just want to share my joyful experience about HACK VANISH CREDIT SPECIALIST. Before the coronavirus pandemic, I had criminal Judgments, few evictions, and late payment which negatively impacted my credit score down to 487 and left me in difficult financial situation, as a single mum of 3, I needed a loan to keep the family running after I lost my husband as a result of COVID-19, all hope were lost, until Mrs. Olivia referred me to HACK VANISH, a credit genius who was very helpful in fixing my credit 6 days after I reached out to him via Email: hackvanish (At) gmail (Dot) com and Phone: +1(747) 293-8514, throughout the process, I felt so involved because an open line of communication was maintained till I got my FICO score restored to 796, currently my loan application has been approved. If you need to hire a credible hacker, HACK VANISH is highly recommended.

    ReplyDelete

  3. RELIABLE BUSINESS/HOME/COMPANY/PROJECT/PERSONAL LOAN? AFFORDABLE LOAN IS HERE FOR YOU TODAY Email profdorothyinvestments@gmail.com

    We are financial consultants providing reliable loans to individuals and funding for business, home and projects start up. Are you tired of seeking loans or are you in any financial mess. Do you have a low credit score, and you will find it difficult to get loans from banks and other financial institutions? then worry no more for we are the solution to your financial misfortune. we offer all types of loan ranging from $5,000.00 to $2,000,000.00USD with a low interest rate of 2% and loan duration of 1 to 33 years to pay back the loan secure and unsecured. Are you losing sleep at nights worrying how to get a Legit Loan Lender? Contact us via Email: profdorothyinvestments@gmail.com

    Do you have a bad credit? Do you need money to pay bills? Do you need loan to buy, refinance or renovate your home? Is it necessary to start a new business? Do you have an unfinished project due to poor funding? Do you need money to invest in any specialty that will benefit you? MRS. DOROTHY LOAN INVESTMENTS aims is to provide excellent professional financial services which include the followings

    * Personal loans * Business loans
    * Home loans * Farm Loans
    * Education loans * Debt consolidation loans
    * Truck Loans * Car Loans
    * Hotels Loans * Refinancing Loans
    * Venture capital and many more.

    We are certified, reliable, financially powerful, fast and dynamic, with no credit check and offers a 100% guarantee loans and finances

    Best Regards
    Prof. Dorothy Pilkenton Jean
    profdorothyinvestments@gmail.com

    ReplyDelete